educative.io

Long polling, why not send to user B chat server directly?

Long polling is to receive messages only, right?

User A should send message directly to user B connected server. The message flow chart does not make sense, why User A need to send to his own chat server first, his chat server is only to receive message sent to him.

Long polling will be for communication.It should be for friends status,messages etc.I think we will have separate poll request or better to use websockets.

Websocket is a different story. Do you mean sending a msg needs to do a new poll request (terminate the existing one)?

We need communications for

  1. Sending messages
  2. Getting friends status
  3. Reeving messages
  4. and so on…

It would better to have a web socket connection where we can exchange different type of info b/w client and server in real time.

If we go with long poll approach, i am not sure how will we handle different type of requests, i think there is to be a long poll request for each operation(from above 4) we want to perform.

For polling of new messages, it will be a frequent poll request,but for sending messages, we can initiate a new request whenever we want to send messages.

For retrieving status of friends can be a less frequent request .

So as i see, if we got by polling, we have different requests.
Let me know your thoughts

I don’t understand that why sending msg needs to use long poll request. The polling is for receiving from the server, whether it is msg or status, etc.

yeah agree.I was wrong at send message part. You will send poll for getting updates like friends status,new messages etc. and there would be different poll request for each.Now tell me you doubt if we are on same page

as i saw your question why cant A can send to B directly right?Because A does not know where is B.A has to ask his server to send message to B.Then A’s server will contact hashTable or some session service holding (userid to connection mapping) to find out which server is serving B connection(if he/she is online) and then send to that server.

yes, I did not ask clearly. I meant why not send the message to any server that can send to B connected server, why do we need to send to A connected server first? I think sending message does not need long polling, only receiving msg needs it.

Sending message dont need long polling: Yes u are correct.

For your other doubts, why cant A send directly to B?
This chapter of book is confusing, because they always they always says that push can be done by longpolling/websockets but these are different beasts.
Now i was implementing this thing with websockets, and that why i told you A has to send to A server which has info which server socket is B connected and then message sent to B.Make sense right?Now this is what book also meant.

You doubt is genuine because you are using long polling , and in that we are just sending HTTP ajax request only with more poll time , and we can send to any server that B can send.

Now you can decide what to use?Long polling or websocket and entire flow changes.

I hope i am clear?

Thanks for clarifying this. Websocket is different, it’s bidirectional.

hello