Closing connection from client and other questions

17 views
Skip to first unread message

rishav...@gmail.com

unread,
Jun 19, 2014, 9:12:32 AM6/19/14
to soc...@googlegroups.com
Hi
My JS knowledge is at the beginner level so please bear with me.

I have a few questions regarding sockjs:
  • How can i close a connection from client side? I know that closing the browser tab closes the connection, but i also want to be able to close the connection on a button press. I couldnt find the method i need to invoke for  this on the sockjs site.\
var sock = new SockJS('/echo');

function closeConnection () {
    sock.end();
}


  • How can i open a new connection from client side by clicking on a button? I am using

var sock = new SockJS('/echo');

sock.onopen = function() {
    addText("You have JOINED the session");
};

to start a new connection on page refresh. but i dont think i should do the same on clicking the button.
  • Does sockjs have the conecpt of channels/lobby/rooms? I want to implement chat rooms with max 10 connection for each room. I suppose functionally i can achieve the same by assigning a channeld to each connection object and write in my own code for the channel logic, but i was wondering if there's something like this baked in the library.
  • In case, you want to check my simple code, you can see it here;
https://github.com/rishavs/sockjsEcho

Thank you.
Reply all
Reply to author
Forward
0 new messages