Here is the client inside Game Engine… I’m using the following library for this.
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.