sockjs icon indicating copy to clipboard operation
sockjs copied to clipboard

About Using Websocket

Open kuyeon opened this issue 3 years ago • 2 comments

How to send data from server client, by websocket?

Any simple example code?

kuyeon avatar Aug 27 '21 07:08 kuyeon

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

jersobh avatar Aug 31 '21 09:08 jersobh

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

kuyeon avatar Sep 02 '21 00:09 kuyeon