- Home /
UnitySocketIO sending a websocket message to nodejs
Just wondering if anyone has used the UnitySocketIO to chat between unity and node.js.
I want to send a message but the documentation is lacking and everyone has a different way of doing it without explaining key aspects to setting it up.
In Unity(C#) i set it up like this:
using UnityEngine;
using System.Collections;
using SocketIOClient;
public class Gui : MonoBehaviour {
void OnGUI () {
// Make a background box
GUI.Box(new Rect(10,10,100,90), "Loader Menu");
// Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
if(GUI.Button(new Rect(20,40,80,20), "Level 1"))
{
Debug.Log("Button 1");
}
// Make the second button.
if(GUI.Button(new Rect(20,70,80,20), "Socket test"))
{
string socketUrl = "http://127.0.0.1:8001";
Debug.Log("socket url: " + socketUrl);
Client client = new Client(socketUrl);
client.Send("Hello world");
}
}
}
My node server is set up like this to recieve the message:
io.sockets.on("connect", function(socket)
{
socket.on("Hey", function(data)
{
console.log(data);
});
});
Im not sure how it works I tried to iplement the "Hey" into the send in unity as I would with any other client but it does not allow multiple parameters. Any insight would be great!!
A tip is to to use a tool to monitor network (like tcpdump from linux) to see what is going on.
Answer by sotirosn · Jun 25, 2016 at 01:49 AM
You probably want to monitor the sockets 'data' event in nodejs, I doubt it emits an event 'hey'. socket.on('data', function(data) { console.log(data); });
Your answer
![](https://koobas.hobune.stream/wayback/20220613153451im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Can't generate apk 1 Answer
Run Function when user shakes mobile andriod unity c# 0 Answers
Deploying a Unity app to Android phone(s) - Issue. 0 Answers
Unity looses my Player settings 1 Answer