Hi, I’m trying to simply connect to ANY kind of socket server with Unity personal edition (preferably with native WebSocket support but I’m not sure if that’s possible in the WebGL player with the Unity Free version, let me know if there’s ANY workaround though).
SO currently I’m trying to simply connect to a socket.io server running on node.js, here’s the code for the server (works PERFECTLY if I connect on a JavaScript client):
var http = require(“http”);
server = http.createServer((req,res) => {
res.write(“Welcome”);
res.end();
});
server.listen(8000, () => {
console.log(“doin it”);
});
var io = require(“socket.io”)(server);
io.on(“connection”, (sock) => {
console.log(“WOW can’t believe it”);
});
SO Now the Unity part:
I’ve been looking online for the right library and I found this: GitHub - NetEase/UnitySocketIO: socket.io client for unity3d. · GitHub
however, when I try to connect, I’m getting an error in unity:
Error initializing handshake with http://localhost:8000/
here is my unity code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class main : MonoBehaviour {
// Use this for initialization
void Start () {
print(“testing?”);
var cli = new SocketIOClient.Client(“http://localhost:8000”);
cli.On(“connect”, (fn) =>
{
print(“did I connect?”);
});
cli.Error += (sender, e) => {
print(e.Message.ToString());
};
cli.Message += onsend;
cli.Connect();
cli.Send(“hi?”);
print(“tried?”);
cli.Close();
}
void onopen(object sender, SocketIOClient.MessageEventArgs e)
{
print(e.Message);
}
void onsend(object sender, SocketIOClient.MessageEventArgs e)
{
print(e.Message);
}
// Update is called once per frame
void Update () {
}
}
on stackoverflow there was an answer to the problem by downgrading the socket.io to 0.9.x, but I don’t want to do that.
DOES anyone know how to simply connect to a socketIO server with the FREE version of unity? If any other kind of library at all is available, that would be great, I’ve been looking on the forums here and couldn’t find anything really.