socket.io-client-csharp icon indicating copy to clipboard operation
socket.io-client-csharp copied to clipboard

Unity .net / nodejs problem

Open blenderino100 opened this issue 3 years ago • 8 comments

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!

blenderino100 avatar Dec 12 '21 01:12 blenderino100

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();
        // ^^^^^^^^^^^^^^^
    }

doghappy avatar Dec 12 '21 01:12 doghappy

Thanks for the quick response!

Yes that was the problem!

blenderino100 avatar Dec 12 '21 01:12 blenderino100

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/

jcortezzo avatar Dec 16 '21 06:12 jcortezzo

@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

blenderino100 avatar Dec 16 '21 15:12 blenderino100

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

TiagoSantos01 avatar Dec 29 '21 10:12 TiagoSantos01

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.

devprog-dev avatar Jan 10 '22 14:01 devprog-dev

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 avatar Apr 06 '22 21:04 jurniores

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

jurniores avatar Apr 06 '22 23:04 jurniores