UnitySocketIO icon indicating copy to clipboard operation
UnitySocketIO copied to clipboard

error initializing handshake for secure connection

Open vrwalking opened this issue 12 years ago • 14 comments

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

socket = io.connect('https://abcd.com:321010', {secure: true});

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

vrwalking avatar Jul 23 '13 11:07 vrwalking

The https is secure, so you do not need to add the second argument "{secure: true}".

halfblood369 avatar Jul 25 '13 03:07 halfblood369

so unitysocketio can be used for secure socket.io communication?

vrwalking avatar Jul 25 '13 07:07 vrwalking

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

vrwalking avatar Jul 25 '13 12:07 vrwalking

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.

vrwalking avatar Jul 25 '13 18:07 vrwalking

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");

valyard avatar Aug 13 '13 00:08 valyard

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.

vrwalking avatar Aug 13 '13 12:08 vrwalking

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.

valyard avatar Aug 13 '13 13:08 valyard

ya you are correct it will capitalize any name and args.If you have cross working problem there can be two possiblites:

  1. json framework 2.improper json data coming in i too had some troubles with that.

vrwalking avatar Aug 13 '13 13:08 vrwalking

@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.

halfblood369 avatar Oct 12 '13 07:10 halfblood369

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.

vrwalking avatar Oct 12 '13 07:10 vrwalking

Did you have a try to use https to connect the secured servers? And your secured servers must support https service.

halfblood369 avatar Oct 12 '13 08:10 halfblood369

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...

vrwalking avatar Oct 12 '13 08:10 vrwalking

Thanks for your time, i will have a try to check it out.

halfblood369 avatar Oct 12 '13 08:10 halfblood369

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?

eonyanov avatar Sep 08 '14 05:09 eonyanov