doghappy / socket.io-client-csharp

socket.io-client implemention for .NET
MIT License
729 stars 125 forks source link

Unity .net / nodejs problem #244

Open blenderino100 opened 2 years ago

blenderino100 commented 2 years ago

Hello! I would like to ask for help. What could be the problem?

Unity Client

using UnityEngine;
using SocketIOClient;

public class NetworkClient : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        var client = new SocketIO("http://localhost:3000/");
        client.On("connection", socket => {
            Debug.Log("test");
        });
    }
    // Update is called once per frame
    void Update()
    {

    }
}

NodeJS server


const io = new Server();

io.on("connection", (socket) => {
  console.log("test 2")
});

io.listen(3000);

I start both and for some reason there is no communication. What am I wrong about? Thank you in advance for your answer. Have a nice day!

doghappy commented 2 years ago

Is there a line of code missing?

    void Start()
    {
        var client = new SocketIO("http://localhost:3000/");
        client.On("connection", socket => {
            Debug.Log("test");
        });
        await client.ConnectAsync();
        // ^^^^^^^^^^^^^^^
    }
blenderino100 commented 2 years ago

Thanks for the quick response!

Yes that was the problem!

jcortezzo commented 2 years ago

Hi @blenderino100 , how did you get SocketIO working with Unity? I think our connection is not working since we are using an older version (2.x) of SocketIO, but the top plugin on NuGet by HeroWong's DLLs did not play nice with Unity. I do not think it is a problem with the code, we get a response from Unity saying that the connection is not open.

This is what we tried to install the DLLs from that didn't work: https://www.nuget.org/packages/SocketIOClient/

So here is what we actually used: https://www.nuget.org/packages/SocketIOClient.NetFx/

blenderino100 commented 2 years ago

@jcortezzo Hi I create a new 2.0 .net and installed SocketIOClient build > after in console > dotnet publish and copied the new files to a unity project it works without errors

TiagoSantos01 commented 2 years ago

bros, I use this extersion to download the stuff in nuget in unity and it still shows if it has an update https://github.com/GlitchEnzo/NuGetForUnity

devprog-dev commented 2 years ago

I created Unity Sample https://github.com/devprog-dev/UnitySocketIOPlugins

don't click link, just copy and paste on web browser

check it. referenced it here.

jurniores commented 2 years ago

I created Unity Sample https://github.com/devprog-dev/UnitySocketIOPlugins

don't click link, just copy and paste on web browser

check it. referenced it here.

in my project it didn't work

jurniores commented 2 years ago

I created Unity Sample https://github.com/devprog-dev/UnitySocketIOPlugins

don't click link, just copy and paste on web browser

check it. referenced it here.

Your plugins folder is all in Meta