ghedipunk / PHP-Websockets

A Websockets server written in PHP.
BSD 3-Clause "New" or "Revised" License
917 stars 374 forks source link

Socket error: Connection reset by peer, when Nmap #21

Closed guillaumeinnov24 closed 9 years ago

guillaumeinnov24 commented 9 years ago

(great job btw!) I'm still on the example. Launching testwebsock.php works fine, but asa a nmap scan occured, a RST packet is received and the connection fail fatally. Dropping data.

Server started Listening on: 0.0.0.0:9000 Master socket: Resource id #6 Client connected. Resource id #7

Socket error: Connection reset by peer

nmap 192.168.0.10 -p9000

guillaumeinnov24 commented 9 years ago

it may come from:

    $numBytes = @socket_recv($socket,$buffer,$this->maxBufferSize,0);
      if ($numBytes === false) {
        throw new Exception('Socket error: ' . socket_strerror(socket_last_error($socket)));
      }

    PHP Fatal error:  Uncaught exception 'Exception' with message 'Socket error: Connection reset by peer'

    *** thrown in PHP_Websockets/WebSockets.php on line 98 ***
ghedipunk commented 9 years ago

I'll have to play with nmap to see what it's actually doing.

From your messages, it looks like both nmap and the server think that the other is closing the connection.

I'll start putting in additional error handling. The worst that nmap should be seeing would be a HTTP 400 error, but it seems that the unhandled exception is terminating the server for a simple closed connection before the handshake is complete.

Things I'm adding on my to-do list:

Log uncaught exceptions (especially during handshake) rather than terminating, with verbose complaining output to the terminal.

Investigate nmap's behavior.

ghedipunk commented 9 years ago

Unusual client disconnects (or any socket error, for that matter) no longer throw an exception.