javascript - What is the websockets server location for this code? -
i have socket.io client code has been tested work server.
<script> // create new websocket var socket = io.connect('http://localhost:8000'); // on message received print data inside #container div socket.on('notification', function (data) { var userslist = "<dl>"; $.each(data.users,function(index,user){ userslist += "<dt>" + user.user_name + "</dt>\n" + "<dd>" + user.user_description + "\n" + "<figure> <img class='img-polaroid' width='50px' src='" + user.user_img + "' /></figure>" "</dd>"; }); userslist += "</dl>"; $('#container').html(userslist); $('time').html('last update:' + data.time); });
i tried use simple web socket client tester software. 1 using chrome extension "simple web socket client".
i need key in url websockets server. keyed in
ws://localhost:8000/notification
it did not work. got "undefined" error. url should key in websockets server?
here relevant server code.
// creating server ( localhost:8000 ) app.listen(8000); var updatesockets = function(data) { // adding time of last update data.time = new date(); console.log('pushing new data clients connected ( connections amount = %s ) - %s', connectionsarray.length , data.time); // sending new data sockets connected connectionsarray.foreach(function(tmpsocket) { tmpsocket.volatile.emit('notification', data); }); };
edit:both server , client developed using socket.io
Comments
Post a Comment