Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

socket.volatile.emit from client side

I am developing a simple application, with a node.js server, and an HTML5 client in browser. At the moment, I am using socket.io for the communication, because it seems to me that it should work in most cases: proxies, firewalls, etc. On the other hand, I find hard to now precisely what is going on, as a lot of things are automated, and as I did not find a comprehensive documentation. One other important point is that I am new to the Javascript/Node.js world.

In this particular question, I am trying to achieve a tight synchronisation between clients and a server, following an SNTP-like scheme. Therefore, I would like to drop any delayed packet. The volatile flag should allow me to do this, and I use it on to emit messages from the server, but it does not seem valid from the client side. Is it by design? Because I am using the stand-alone version on the client (no require or browserify here)?

index.html

<html>
    <body onload="init()">
        <script src="/socket.io/socket.io.js"></script>
        <script src="calibration.js"></script>
    </body>
</html>

calibration.js

var socket = io.connect();
function init() {
   socket.emit('test', 'ok');
   socket.volatile.emit('test-volatile', 'bad');
}

console log on page load

socket.volatile is undefined

Is volatile pointless from the client side anyway? If not, is there a way to use it? Any pointer to documentation would be appreciated. At the moment, I am considering engine.io or ws node.js packages...

like image 897
jipodine Avatar asked Feb 11 '26 03:02

jipodine


1 Answers

I think sending volatile messages from the client to the server is not supported yet.

https://github.com/socketio/socket.io-client/issues/283

https://github.com/socketio/socket.io-client/pull/821

like image 125
joscas Avatar answered Feb 13 '26 16:02

joscas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!