aio-libs / sockjs

SockJS Server
Apache License 2.0
118 stars 40 forks source link

About Using Websocket #445

Open kuyeon opened 3 years ago

kuyeon commented 3 years ago

How to send data from server client, by websocket?

Any simple example code?

jersobh commented 3 years ago

Use the sock.send function:

var sock = new SockJS('https://mydomain.com/my_prefix');
 sock.onopen = function() {
     console.log('open');
     sock.send('test');
 };

 sock.onmessage = function(e) {
     console.log('message', e.data);
     sock.close();
 };

 sock.onclose = function() {
     console.log('close');
 };

See client documentation

kuyeon commented 3 years ago

Thank you for answer. By the way, I meant the server-side example code, may I ask for one?