Php ratchet websocket $conn->send($msg)! How to get this messenge in client? -


here code (websocket php using rachet , wamp server!

public function onclose(connectioninterface $conn) {   $conn->send("close client"); } 

i using $conn->send() send message client don't know how message using autobahnjs on client?

update found sulutions problem!

1) enabled debug mode in autobahnjs

ab.debug( true, true ); 

2) using conn._websocket.onmessage every messenge response server.

conn._websocket.onmessage = function (e){     data = json.parse(e.data);     console.log(data[1]);     if(data.cat=='serverevents'){     switch(data.action) {         case 'updateserverinfo':               jquery.updateserverinfo(data.actiondata);         break;             }         }     }; 

thanks all.

autobahnjs has own way of handling client requests made server. trying send request server (a "close clients" request) clients. best way this, have thread that's polling server events every x seconds, using js's setinterval() function. e.g.:

setinterval(checkforupdate, 60 * 1000);

and in checkforupdate():

function checkforcontentupdate(timetableid) {     var serviceurl = 'http://yourscripttocheckhere';      var xhr = $.ajax({url: serviceurl, cache: false, success: function(content) {       // check server reply , act accordingly     }}); } 

Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -