1

I have a problem with WebSocket4Net where I get error when opening a connection, and the connection is closed then.

The problem as follow:

I connect using the following code:

Dim objWebSocket As WebSocket
objWebSocket = New WebSocket(WebsocketURL)
objWebSocket.Security.AllowNameMismatchCertificate = True
objWebSocket.Security.AllowCertificateChainErrors = True
AddHandler objWebSocket.Opened, AddressOf WebSocket_Opened
AddHandler objWebSocket.Error, AddressOf WebSocket_Error
AddHandler objWebSocket.Closed, AddressOf WebSocket_Closed
AddHandler objWebSocket.MessageReceived, AddressOf WebSocket_MessageReceived
objWebSocket.Open()

The callback functions are:

Private Sub WebSocket_Opened(sender As Object, e As System.EventArgs)

End Sub

Private Sub WebSocket_Error(sender As Object, e As SuperSocket.ClientEngine.ErrorEventArgs)

End Sub

Private Sub WebSocket_Closed(sender As Object, e As System.EventArgs)

End Sub

Private Sub WebSocket_MessageReceived(sender As Object, e As WebSocket4Net.MessageReceivedEventArgs)

End Sub

When I call objWebSocket.Open(), The function WebSocket_Error is fired with exception : HTTP /1.1 200, then the connection is closed.

Please advice

selfstudy
  • 523
  • 2
  • 15
Ali Ahmad
  • 11
  • 1
  • Have you tried it with a test site such as `wss://echo.websocket.org/`? I don't think it will work with HTTP. – Andrew Morton Aug 26 '18 at 16:18
  • I have tested it with : wss://ws.weatherflow.com/swd/data?api_key=20c70eae-e62f-4d3b-b3a4-8586e90f3ac8 , and worked with no errors, but with other sites it does not, and returns HTTP/1.1 200, what is that means ( HTTP/1.1 200)? – Ali Ahmad Aug 26 '18 at 22:14
  • Looking at the [websocket protocol handshake](https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake), I would *guess* that the server does not work with websockets as it appears that it is giving a response of HTTP/1.1 200 ("OK") instead of HTTP/1.1 101 ("Switching protocols"). You could use something like Wireshark or Fiddler to investigate more deeply if you are sure the server does work with websockets. – Andrew Morton Aug 27 '18 at 14:59

0 Answers0