Send message through websocket using javascript -


i connecting websocket server using javascript , play framework. having trouble understanding proper way make use of websocket.send() method of websocket.

 $(function() {      //depending on browser have use websocket or mozwebsocket     var ws = window['mozwebsocket'] ? mozwebsocket : websocket;     var websocket = new ws('ws://localhost:9000/websocket');      websocket.onopen = function() {         websocket.send('test');     }     //split message websocket type, user , text     //uses nifty regular expression     websocket.onmessage = function (event) {         $('.output').append(event.data);     } }); 

when use send() outside onopen event error because send() not available. thinking there must event dynamically execute send() without onopen event (afaik) executes when connection opens up.

thanks!

onopen correct event handler use handler used when connection ready used.

the api docs show 4 event handlers onopen onmessage onerror onclose

api doc


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -