Jump to content

socket_read() error


The Little Guy

Recommended Posts

I have a socket server that is running on a while loop, the server listens for something to write to the stream, when something does write to the stream the server prints out the following:

 

Warning: socket_read(): unable to read from socket [107]: Transport endpoint is not connected

 

It fails on this line: $read = socket_read($socket, $length); with the above error (found in method "hear")

 

What does the error mean, and how can I fix it? any thoughts would be great!

 

Server:

require_once 'phpLive.php';
$live->listen(function(){
global $live;
if(($heard = $live->hear())){
	echo "I heard: $heard\n";
}
});

 

Class:

public function hear($socket_id = 0, $length = 1024){
	if(!isset($this->sockets[$socket_id]))
		$socket_id = $this->socket_connect();
	$socket = $this->sockets[$socket_id];
	if(is_resource($socket)){
		$this->allow($socket_id);
		$read = socket_read($socket, $length);
		if(is_string($read)){
			$this->quick_string = $read;
			$this->function_name = __FUNCTION__;
			return $this;
		}
	}
	return false;
}
public function allow($socket_id = 0){
	if(!isset($this->sockets[$socket_id]))
		$socket_id = $this->socket_connect();
	$socket = $this->sockets[$socket_id];
	socket_accept($socket);
	$this->function_name = __FUNCTION__;
	return true;
}

 

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/247406-socket_read-error/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.