- Home /
SocketIO how to read values from data
Hello,
I am trying to make a multiplayer game with NodeJS, SocketIO and Unity. I know how socket io works, but i don't know how to get the values on the client side. This is the server code i have tried:
var io = require('socket.io')({
transports: ['websocket'],
});
io.attach(4567);
io.on('connection', function(socket){
socket.emit("hello, {
info: "hello",
}");
socket.on("hi", function(data) {
console.log("conenction works");
});
});
and this is the unity code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using SocketIO;
public class _networker : MonoBehaviour
{
private SocketIOComponent socket;
public void Start()
{
GameObject go = GameObject.Find("SocketIO");
socket = go.GetComponent<SocketIOComponent>();
socket.On("hello", function(e){
Debug.Log(e.data.info);
socket.Emit("hi");
});
}
}
The problem is that the debugger gives me Null instead of "hello". Does anyone know how to fix this?
Comment
Answer by thelghome · Jun 16, 2020 at 04:03 PM
FM WebSocket may fit your need.
asset store: http://u3d.as/1DH3
Your answer

Follow this Question
Related Questions
Yet another socket-and-crossdomain-policy question 1 Answer
Uniweb(sockets) + Facebook 0 Answers
Socket connection on Android/IOS/Windows 1 Answer
How to run javascript socket.io functions from game 0 Answers
Using Job System to Poll Sockets 0 Answers