into this problem and wanted to know your opinions on different solutions to it.
As you know in HTTP we often expect a request and a response and then connection is closed. But in raw TCP you don't know if the data you receive from a server is a response to a previous request or an event.
Basically what I'm trying to do is to have a non-closing (persistent) HTTP connection using raw TCP.
It's a chat application where I can send a request to search for a specific user and wait for response and also receive events related to a specific user.
What i'm currently doing is assigning id to requests that need responses and have a for loop waiting for responses to each request but I'm thinking this is the wrong way.
What do you think?
> and then connection is closed. No, not necessarily. Usually, web servers implement the HTTP keep-alive feature which, obviously, keeps the underlying TCP/IP connection alive for a while > Basically what I'm trying to do is to have a non-closing (persistent) HTTP connection using raw TCP. Why? > It's a chat application where I can send a request to search for a specific user and wait for response and also receive events related to a specific user. So you want to build a chat app, right? There are several options, one of which is probably the simpliest: 1. use HTTPS for client->server communication (REQ/REP topology) 2. use HTTP/2 SSE (Server-Sent Events) for server->client communication (PUB/SUB topology) keep in mind that HTTP/2 SSE doesn’t work on old IE browsers, if that’s important to you (f*ck IE)
Обсуждают сегодня