node.js - Setting up a Stateless connection with NodeJS and Socket.IO -
after prototyping project using php , unity3d i've decided on building production version using cordova , nodejs.
i'm using socket.io nodejs , having confusion connections. way had expected work out following procedure:
- the client connect server request
- the server respond request
- the connection closed
however, seems connection likes stay open, , if connection closed, continuously attempts reconnect not looking for. i'm attempting establish single state of data transfer, similar happens when make web-request php file.
the source code of project pretty boilerplate code:
var application = require('express')(); var http = require('http').server(application); var server = require('socket.io')(http); http.listen(8080, function() { console.log('listening on *:8080'); }); server.on('connection', function(socket) { console.log('server: new connection has been received.'); server.on('disconnect', function() { console.log('server: connection has been closed.'); }); });
i not need persistent connection, nor want one.
thoughts: send close handshake client. example:
- send data server
- recieve data server
- send close request server / close socket
- continue application logic once socket closed
would proper way handle this? question arises, if data gets lost, there's permanently open socket. implementing basic timeout ideal in situation? (ie: if response isn't received within 10 seconds, there error or server not available).
then socket.io wrong tool scenario. socket.io needs keep socket open events server client (and vice-versa). matter of fact, of server not support websockets, socket.io resort other mechanisms, such polling.
Comments
Post a Comment