WebSocketSharp returning "Input string was not in a correct format"

993 Views Asked by At

I have a c# client that I am trying to connect to a websocket server. Using the Chrome extension "Simple Web Socket Client", I can connect, and send commands ok to the websocket server so I know the server is working ok and it is a commerical product.

I am trying to use the library WebSocketSharp and I get this error while trying to connect to the socket. Just so you know there are no proxy servers in play and the server is on the internal network.

2/03/2018 4:05:00 PM|Fatal|WebSocket.Connect|WebSocketSharp.WebSocketException: An exception has occurred while reading an HTTP request/response. ---> System.FormatException: Input string was not in a correct format.
                          at System.Version.VersionResult.SetFailure(ParseFailureKind failure, String argument)
                          at System.Version.TryParseComponent(String component, String componentName, VersionResult& result, Int32& parsedComponent)
                          at System.Version.TryParseVersion(String version, VersionResult& result)
                          at System.Version.Parse(String input)
                          at System.Version..ctor(String version)
                          at WebSocketSharp.HttpResponse.Parse(String[] headerParts)
                          at WebSocketSharp.HttpBase.Read[T](Stream stream, Func`2 parser, Int32 millisecondsTimeout)
                          --- End of inner exception stack trace ---
                          at WebSocketSharp.HttpBase.Read[T](Stream stream, Func`2 parser, Int32 millisecondsTimeout)
                          at WebSocketSharp.HttpRequest.GetResponse(Stream stream, Int32 millisecondsTimeout)
                          at WebSocketSharp.WebSocket.sendHttpRequest(HttpRequest request, Int32 millisecondsTimeout)
                          at WebSocketSharp.WebSocket.sendHandshakeRequest()
                          at WebSocketSharp.WebSocket.doHandshake()
                          at WebSocketSharp.WebSocket.connect()

Using wireshark I followed the stream and got this as part of the handshake

  GET / HTTP/1.1
  User-Agent: websocket-sharp/1.0
  Host: 192.168.0.29:55537
  Upgrade: websocket
  Connection: Upgrade
  Sec-WebSocket-Key: o0Smz22nOFWLW/3hvyvYQQ==
  Sec-WebSocket-Extensions: permessage-deflate; server_no_context_takeover; client_no_context_takeover
  Sec-WebSocket-Version: 13

  ....HTTP/1.1 101 Switching Protocols
  Connection: Upgrade
  Upgrade: websocket
  Sec-WebSocket-Accept: guJWynqtY1ZrPq+m6bfUGE2yJvA=

Any idea? I've even tried WebSocket4Net and that also had an issue connecting.

0

There are 0 best solutions below