Open vrwalking opened 11 years ago
The https is secure, so you do not need to add the second argument "{secure: true}".
so unitysocketio can be used for secure socket.io communication?
one more thing i would like to ask on this thread, i have seen that told already in many issue threads. why socket.emit command is not working. Its working in socketio4net . If its not developed, it would be nice if you can enlighten how should i move to get it worked
I have done some digging into the code and after some test i found that, the Event Message is not encoded properly. The code i used is :
IMessage msg = new EventMessage("myevent","{\"jsondata\":\"data\"}",string.Empty,null);
and the msg.Encode shows this:
5:::{"Name":"myevent","Args":["{\"jsondata\":\"data\"}"]}
see the capitalzation of Name and Args, so the server doesn't consider this as an event message. I feel that something similar is causing the socket.On triggering also.
Could you specify which part of the code is handling this,to correct this problem, so that this library is complete, easy client for socketio.
This is because how SImpleJSON works. If a field has name Args it will serialize it to Args. But Socket.io expects args in low case. The same thing happens when data is sent from Socket.io. I don't know how this hasn't been found before because the code doesn't work o.O
Had to add this line for now: evtMsg.MessageText = evtMsg.MessageText.Replace("name", "Name").Replace("args", "Args");
thank you for the reply valyard, i had done this solution already and worked but that change is not enough for emit and socket.on to work.The change has to be done to Messages/Helpers/jsonEncodedEventMessage.cs, to two functions that serialize and deserialize the data.We have to change incoming data to capitalized Name and Args for the proper event firing.
public string ToJsonString()
{
//return SimpleJson.SimpleJson.SerializeObject(this);
string jsonString = SimpleJson.SimpleJson.SerializeObject(this);
jsonString = jsonString.Replace("Name","name").Replace("Args","args");
return jsonString;
}
public static JsonEncodedEventMessage Deserialize(string jsonString)
{
jsonString=jsonString.Replace("name","Name").Replace("args","Args");
JsonEncodedEventMessage msg = null;
try { msg = SimpleJson.SimpleJson.DeserializeObject<JsonEncodedEventMessage>(jsonString); }
catch (Exception ex)
{
Trace.WriteLine(ex);
}
return msg;
}
Another thing i am encountering is that i am unable to connect to secure servers. On deep investigation the error is unsupported hashing algorithm/encryption, in unity. Can that be a unity mono issue, since it is working nicely on socketio4net.
This isn't a good solution since you can have other occurances of "Name" and "Args" in your data (8
I'm strugling with windows version which doesn't work for some reason )8 The same code on OS X works. And I know nothing about secure servers and hashing methods used in this case.
ya you are correct it will capitalize any name and args.If you have cross working problem there can be two possiblites:
@vrwalking Yes, socket.emit command is not working now. If you want it work, maybe the case https://github.com/NetEase/pomelo-unityclient/blob/master/pomelo-unityclient/pomelo-unityclient/EventManager.cs help you.
thanks halfblood... but is there any way i can get unitysocketio to work with secured servers? as per logs its says something like encryption algorithm not supported or such, when trying to connect to secure servers using unitysocketio.So the handshake is failing.
Did you have a try to use https to connect the secured servers? And your secured servers must support https service.
Yes i tried to connect to a server running https service and socket.io and handshake failed. Have you had successful connection with socketio on secured servers? I have tried unitysocketio's parent socketio4net , in visual studio and it connected successfully...
Thanks for your time, i will have a try to check it out.
Hi! I can't connect to sails.js server from Unity3d client. http://stackoverflow.com/questions/25665630/unity3d-unitysocketio-sails-js-error-initializing-handshake Can you help me?
when i tried to connect to secure https server "error initializing handshake" connection is given. The server administrator gave the following as javascript method to connect
but the in socketio the client constructor takes only one argument, the url.How can we pass this second parameter while connecting? or in general how to connect with secure server??
thanks in advance