javascript - jQuery Web Socket not connecting and not sending -


i'm trying convert php function jquery function can use tcp/ip socket local connection straight browser.

i use this:

$socket = @fsockopen('xxx.xxx.xxx.xxx', '8810', $err_no, $err_str);  if(!$socket){     return 'errore #'.$err_no.': '.$err_str; }else{     fwrite($socket, '["d";"c";"?st";200]');     $read = fread($socket, 2024);       //other stuff...      return $read;     fclose($socket);  } 

this works fine. downloaded github jquery websocket 0.0.4 google code site , followed example not successfully.

i tried make connection , send data way:

ws = $.websocket("ws://95.110.224.199:8810/"); ws.send('string', '["d";"c";"?st";200]'); 

this gives me "undefined not function" error.

i tried see if connection establishing (without sending data) way:

var ws = $.websocket("ws://xxx.xxx.xxx.xxx:8810/", {     open: function() {console.log('ws:connesso')},     close: function() {console.log('ws:chiuso')}, }); 

no luck me... console says nothin'... hint or on this? appreciated.

maybe missed jquery.websocket.js file can use javascript web socket:

ws = new websocket('ws://95.110.224.199:8810/');  

or can put 0.0.0.0 in instead of ip because servers not allow direct ip access:

ws = new websocket('ws://0.0.0.0:8810/')  ws.onopen = function(msg) {     // logic opened connection     console.log('connection opened'); }; ws.onmessage = function(msg) {     // handle received data };  ws.onclose = function(msg) {     // logic closed connection     console.log('connection closed.'); } ws.error =function(err){     console.log(err); // write errors console } 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -