Finally, I've a TCP socket working on Glitch

Hey, finally I have a TCP socket working on Glitch. I’m using the WebSocket handshaking in order to set up the socket channel, and it works. The socket is opened and I can send data from c# client to node.js glitch app but, there is always a but, I can receive data from client, but I don’t know why I can send anything back. Maybe I’m missing something in my handshake:

Client sends:

GET / HTTP/1.1
Host: tcp-socket.glitch.me
Upgrade: WebSocket
Connection: Upgrade
\n

And then, the server responds (yes, this one is sent to the client :-?):

  HTTP / 1.1 101 WebSocket Protocol Handshake
  Upgrade: WebSocket
  Connection: Upgrade
  \n
  \n

After that, I can send whatever I want from the client to the server but I can’t send anything from server to client.

Heeelp!!!

2 Likes

Nevermind, client issue it works like a charm!

Yes, sending HTTP requests and responses through TCP sockets works, but what about non HTTP data?

No problem, I’m sending binary data from and to the node.js server.

Well, when receiving data I have to be more careful because tcp is a stream type communication and it may not have received all the datagram. I use a simple protocol in which the first two bytes indicate the length of the datagram.

All received data is stored in a circular buffer for later processing into datagrams.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.