Good evening. I launch the web socket server on the computer and try to connect to it through the client. If I register localhost: 8082 in the client, it will connect, but as soon as I try to register the global ip of the computer instead of the host locale, the client refuses to connect. Here is the client
<script> window.onload = function(){ var socket = new WebSocket("ws://ip:8082"); var status = document.querySelector("#status"); socket.onopen = function() { status.innerHTML = "cΠΎΠ΅Π΄ΠΈΠ½Π΅Π½ΠΈΠ΅ ΡΡΡΠ°Π½ΠΎΠ²Π»Π΅Π½ΠΎ" + "<br>"; }; socket.onclose = function(event) { if (event.wasClean) { status.innerHTML = 'cΠΎΠ΅Π΄ΠΈΠ½Π΅Π½ΠΈΠ΅ Π·Π°ΠΊΡΡΡΠΎ'; } else { status.innerHTML = 'ΡΠΎΠ΅Π΄ΠΈΠ½Π΅Π½ΠΈΡ ΠΊΠ°ΠΊ-ΡΠΎ Π·Π°ΠΊΡΡΡΠΎ'; } status.innerHTML += '<br>ΠΊΠΎΠ΄: ' + event.code + ' ΠΏΡΠΈΡΠΈΠ½Π°: ' + event.reason; }; socket.onmessage = function(event) { status.innerHTML += "ΠΏΡΠΈΡΠ»ΠΈ Π΄Π°Π½Π½ΡΠ΅ " + event.data + "<br>"; }; socket.onerror = function(event) { status.innerHTML = "ΠΎΡΠΈΠ±ΠΊΠ° " + event.message; }; //Π² ΡΠ°ΠΌΠΊΠ°Ρ
onload document.forms["messages"].onsubmit = function(){ var fname = this.fname.value; var msg = this.msg.value; socket.send(fname + ' ' + msg); return false; } } </script> Here is the server code
<?php use Ratchet\Server\IoServer; use Ratchet\Http\HttpServer; use Ratchet\WebSocket\WsServer; use MyApp\Chat; require dirname(__DIR__) . '/vendor/autoload.php'; $server = IoServer::factory( new HttpServer( new WsServer( new Chat() ) ), 8082 ); $server->run();