Asynchroneous answer to the client with nodejs and socket.io... is it possible?

26 views
Skip to first unread message

Bouch Seb

unread,
Sep 25, 2015, 3:16:09 PM9/25/15
to nodejs
Hi, thanks for reading my newbie question. Sorry if it's already in the forum and I didn't find it...
Is it possible to have this sequence with nodejs through socket.io:
1. a client requests the server
2. the server answers and runs a setTimeout function
3. when the setTimeout elapses, the server sends another answer to the client
Easy?
Thanks in advance for your answer.

Zlatko

unread,
Sep 27, 2015, 6:42:56 PM9/27/15
to nodejs
Yes, it is, it's quite easy, if your socket connection persists (or your server and client have means to reconnect if the socket is short-lived).

Example would be something like this:

```
io.on('connection', function(socket){

  socket.on('message', function(msg) {


  })
});
```
Reply all
Reply to author
Forward
0 new messages