问题
I've got a problem with the connection of a client to a socket.io server. I have following code:
private Client _Client;
private void Initialize(string websocket)
{
try
{
this._Client = new Client(websocket);
this._Client.Connect();
if (!this._Client.IsConnected) throw new Exception("Connection to websocket wasn't successfully: " + this._Client.HandShake.ErrorMessage);
}
catch (Exception ex)
{
Logging.Write("Fehler bei der SocketIO-Connection: " + ex.Message);
Logging.WriteLine("incomplete!", ConsoleColor.Red);
return;
}
Logging.WriteLine("completed!", ConsoleColor.Green);
}
I'm using the websocket-uri
http://127.0.0.1:5116/
When I open that address in browser, it shows me the right socket.io socketserver.
At connection to this socket.io server I get the following error:
Error getting handsake from Socket.IO host instance:
Der Remoteserver hat einen Fehler zurückgegeben: (400) Ungültige Anforderung.
So it is a http error (400) bad request. But why? What can I do? I just tried the following code (a solution from a user from a other question):
System.Net.WebRequest.DefaultWebProxy = null;
But that didn't work for me.
回答1:
I fixed this error by myself. It was very simple. The handshake of the socket.io version 1.0.x isn't the same as in version 0.9.x. And SocketIO4Net only working with socket.io version 0.9.x. I downgraded to version 0.9.17 and now it's working perfectly :)
来源:https://stackoverflow.com/questions/24219763/socketio4net-handshake-error