Hey Com,
Ich fummel da nu schon länger rum, um schaffe es einfach nicht
Mein Client will nicht zum Server connecten (JS zu PHP)
Client
PHP
var ws = new WebSocket("ws://77.21.24.70:20132"); ws.onopen = function() { // Web Socket is connected, send data using send() ws.send("Message to send"); alert("Message is sent..."); }; ws.onmessage = function (evt) { var received_msg = evt.data; alert("Message is received..."); }; ws.onclose = function() { // websocket is closed. alert("Connection is closed..."); };
Der PHP Server
PHP
<?php if(!($sock = socket_create(AF_INET, SOCK_STREAM, 0))) { $errorcode = socket_last_error(); $errormsg = socket_strerror($errorcode); die("Couldn't create socket: [$errorcode] $errormsg \n"); } echo "Socket created \n"; if( !socket_bind($sock, "127.0.0.1" , 20132) ) { $errorcode = socket_last_error(); $errormsg = socket_strerror($errorcode); die("Could not bind socket : [$errorcode] $errormsg \n"); } echo "Socket bind OK \n"; if(!socket_listen ($sock , 10)) { $errorcode = socket_last_error(); $errormsg = socket_strerror($errorcode); die("Could not listen on socket : [$errorcode] $errormsg \n"); } echo "Socket listen OK \n"; while(true) { echo "Waiting for incoming connections... \n"; $client = socket_accept($sock); if(socket_getpeername($client , $address , $port)) { echo "Client $address : $port is now connected to us."; } } ?>
Der Server liegt auf meinem PC als vServer (Debian)
Infos:
Die Portfreigabe: http://prntscr.com/4ggi8e
Die Konsole: http://prntscr.com/4ggigx
Danke für jede Hilfe