1

Goal:

Establish working server-client connection based on websocket protocol between QTcpServer and C# client. For now, via localhost.

Problem:

Server works with telnet client but not with any other client (e.g. C# client, websocket test client chrome plugin). C# client works with C# server or other websocket server (e.g. wss://socketsbay.com/wss/v2/2/demo/). Working in this case means: A connection is established, meaning server and client recognize that by firing some corresponding OnOpen event. Data can be sent both ways.

Monitoring the network activity using WireShark, the following can be observed:

enter image description here

Everything beneath the red line happens, when e.g. the QTcpServer successfully connects with the telnet client. Looks like the expected http handshake. After that, data can be exchanged. On the other hand, the lines above the red line appear if e.g. I try to connect the QTcpServer with a client other than telnet. After the handshake, it looks like the client sends the header of the handshake again? (Direction verified via wireshark: Client->Server). Anyways, after that the client websocket state is stuck on Connecting. The server thinks the connection is established though but data exchange is not possible.

What could be the problem here? I cannot figure out whether it's a server- or client-side problem, since there are scenarios, as mentioned, where both sides work.

anjelomerte
  • 286
  • 1
  • 9
  • A HTTPClient and Websocket are not compatible. Some applications create a relay to interface between the two. – jdweng Oct 27 '22 at 10:51
  • As stated, the websocket protocol is used. However, the underlying handshake at the beginning of a websocket based interaction is still carried out as http requests as far as I know. – anjelomerte Oct 27 '22 at 11:34
  • A websocket will not connect to a HTTP server, Both use TCP as the transport layer. HTTP closes connection after a Request/Response. Websocket keeps connection open. So the TCP handshaking to establish the connection is the same. The application level is different. – jdweng Oct 27 '22 at 11:40
  • That is absolutely true. The used server is a ```QTcpServer```. Im just saying that the initial http handshake is successul. The websocket server as well as the client are also both working in combination with others. There is no confusion between http and websocket protocol. Maybe you have got another idea. Thanks for taking your time anyway! – anjelomerte Oct 27 '22 at 11:45
  • HTTP and websocket will NOT directly communicate. Where applications do communicate there is a relay that creates two connections one HTTP to HTTP and second connecting weboscket to websocket. It may appear that there is only one connection but there is really two. – jdweng Oct 27 '22 at 12:07

1 Answers1

1

Turns out the problem was that the server was expecting a regular TCP connection while the clients were all using Websocket protocol on top. Therefore it was not possible to create a working connection, although it seemed like client and server connected.

The following post goes more into detail about the differences between Websockets and regular TcpSockets: Diff websockets and sockets

anjelomerte
  • 286
  • 1
  • 9