Socket Io Client sent messages are not received at the Node Js server.

Here is the client inside Game Engine… I’m using the following library for this.

Socket io

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using SocketIO;

public class Communication : MonoBehaviour {
	
	public GameObject go;
	SocketIOComponent socket;
	Dictionary<string, string> data;    
	
	
	void Start () {
        go = GameObject.Find("SocketIO");
        socket = go.GetComponent<SocketIOComponent>();
        
        data = new Dictionary<string, string>();
        data["email"] = "some@email.com";
		data["pass"] = "1234";		
		Debug.Log("Test123");
        socket.Emit("messages", new JSONObject(data));
	}
	
}

Following is the server that I’m running inside my PC. (Outside Unity)

var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);

app.get('/', function(req, res){
    res.send('<h1>Hello world</h1>')
});

io.on('connection', function(socket){
    console.log('a user connected');

    socket.on('disconnect',function () {
        console.log('User Disconnected...')
    });

    socket.on('messages',function (msg) {
		 console.log('HELLO');
         console.log(msg);
    });

});


http.listen(80, function(){
    console.log('listening on *:80');
});

Client connects to the server but it doesn’t print out the received message. Actually, the following line doesn’t print either.

console.log(‘HELLO’);

Even in the client, following line prints nothing on the console.

Debug.Log(“Test123”);

Am I doing something wrong? Any help is much appreciated.

Hi still need a hand ???

ANYONE HAVE SAME PROBLEM ATTENTION:

  • Because the package work well in the past so what you need is get in the time machine.
  • Or … you can uninstall the SocketIO on your node server and reinstall the older version

i delete version 3, re-install version 2.1.1 and it’s work


cd YourServerPath

npm uninstall socket.io

npm install socket.io@2.1.1


You guys are wellcome :Đ