javascript - Websocket can't connect but not throwing exceptions -
trying create connection websocket in js php server, can't connect server no exception thrown
js
try { var socket; var host = "ws://www.somecoolsite.com:9080/test.php"; var socket = new websocket(host); console.log("opening socket..."); socket.onopen = function () { console.log('socket status: ' + socket.readystate + ' (open)'); socket.send("2"); console.log("sent first package"); } socket.onconsole.log = function (msg) { console.log('received: ' + msg.data); } socket.onclose = function () { console.log('socket status: ' + socket.readystate + ' (closed)'); } } catch (exception) { console.log('error' + exception); }
php on somecoolsite
$server = stream_socket_server("tcp://localhost:9080", $errno, $errormessage); if ($server === false) { throw new unexpectedvalueexception("could not bind socket: $errormessage"); } else { echo "working"; } (;;) { $client = @stream_socket_accept($server); if ($client) { stream_copy_to_stream($client, $client); fclose($client); } }
i'm stuck entire day, can't establish socket connection. has idea can problem here?
please remove part of code
socket.onconsole.log = function (msg) { console.log('received: ' + msg.data); }
you can't "socket.onconsole.log"
in console obtained "socket statut 3(closed)"
please take on link
Comments
Post a Comment