This project is read-only.

Problem Add Headers to get connected

Jun 30, 2014 at 9:14 AM
Edited Jun 30, 2014 at 9:18 AM
Hello,

I have downloaded zip file and added dll reference SocketIO4Net.Client 0.6.26.0 version (Runtime version - v4.0.30319) in my C# project. I got to connect to my server. While connecting I got to pass a token along in headers.
In Client class, I am not able to find a way to add headers directly or thru socket.HandShake class. The Client class also has only 2 constructors with WebSocketVersion and not 4 with NameValueKeyPairs parameters. This is my code :-
        private void init()
        {
            //string url = string.Format("http://api.chat.com:8080/?token={0}", MintWinLib.Helpers.API_Utility.ApiSecret);
            socket = new Client("http://api.chat.com:8080");
           
            socket.Opened += socket_Opened;
            socket.Message += socket_Message;
            socket.Error += socket_Error;
            socket.SocketConnectionClosed += socket_SocketConnectionClosed;
            
            
            socket.On("connect", (fn) =>
                {
                    Console.WriteLine("********** CONNECTED event....");
                    
               });

            socket.On("open", (fn) =>
            {
                Console.WriteLine("On.open Msg - " + fn.MessageText);
            });
            
            socket.Connect();
            
        }
        void socket_Error(object sender, ErrorEventArgs e)
        {
            Console.WriteLine("********** CONNECTION ERRIR event...." + e.Message + "\n HandShake Error = " + socket.HandShake.ErrorMessage);
            Console.WriteLine("********** CONNECTION Exception = " + e.ToString());
        }
I get the following error :-
The thread '<No Name>' (0x201c) has exited with code 0 (0x0).
A first chance exception of type 'System.Net.WebException' occurred in System.dll
********** CONNECTION ERRIR event....Error initializing handshake with http://api.chat.com:8080/
 HandShake Error = Error getting handsake from Socket.IO host instance: Unable to connect to the remote server
********** CONNECTION Exception = SocketIOClient.ErrorEventArgs
Socket Connected --- False
Into SocketHandler CLOSE...........
Error Event: Error initializing handshake with http://api.chat.com:8080/
    System.Exception: Exception of type 'System.Exception' was thrown.
In NuGet and here on site I find the latest version is numbered as 0.6.26.0. On some forums I also read 0.9 and 1.0 versions, but can't get them anywhere. Have looked at many sites for some solution for this but couldn't get any. Is it, that we cannot add headers - I doubt so.

Can anyone please help me - do I need a different version. If so, then from where can I get it ! In current am I doing something wrong to try to add headers. Can anyone please help me solve the problem - where am I going wrong and how to I handle it ? From last 2-3 days I am stuck with this, due to this not able to proceed further.
Coordinator
Jun 30, 2014 at 10:58 PM
Edited Jun 30, 2014 at 10:59 PM
The download zip version has the header / extra constructors - nuget is slightly behind the codeplex source.

If you downloaded the zip, you should see the overloaded constructor - you should be able to do something along the lines of the following, adding any headers you might need:
Console.WriteLine("Starting SocketIO4Net Client Events Example...");
string ioServer = string.Format("https://api.icbit.se/icbit?AuthKey={0}&UserId={1}", authKey, userId);
var headers = new NameValueCollection
     {
        {
             "user-agent",
             "Not-REAL-DEMO - Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1529.2 Safari/537.36"
         }
     };
socket = new Client(ioServer, headers);
Jul 1, 2014 at 9:22 AM
Hi Jim,

I downloaded the zip again today from https://socketio4net.codeplex.com/releases/view/90212 , and you would be surprised that it contains only 2 constructors in the Client class. and they are :-
        public Client(string url)
            : this(url, WebSocketVersion.Rfc6455)
        {
        }

        public Client(string url, WebSocketVersion socketVersion)
        {
        }

        /// <summary>
        /// Initiate the connection with Socket.IO service
        /// </summary>
        public void Connect() {
                }
I added using this technique - http://socketio4net.codeplex.com/discussions/395270 and it gets connected now.

For your reference, the 3rd constructor is not in the currently available download package (zip file).

Thanks.