Jump to content

socket_read() + unix socket


dann0

Recommended Posts

I'm having trouble reading data from a unix socket.

 

i can create the socket and the connection ok and sending data is no problem, but when i try to read or recv the script does not return, if i set the socket to non_blocking i get 'Resource temporarily unavailable'.

 

the socket file i connect to is created by vlc (Video Lan Client) v1.0.1 and my OS is Xubuntu 9.04.

 

my code is

   
   $socket = socket_create(AF_UNIX, SOCK_STREAM, 0) or die('socket not created');
   socket_set_nonblock($socket);
   $conn = socket_connect($socket, '/home/rage/smelly.sock')or die('connection not created');
   $msg = "playlist";
   $len = strlen($msg);
   $byt = socket_send($socket,$msg,$len,0);
   print_r( $byt.' bytes successfully sent to socket ('.$socket.')'.PHP_EOL);

if($buf = socket_read($socket, 4)){
	print_r($buf.PHP_EOL);
}else{
	$err = socket_last_error($socket);
	$errormsg = socket_strerror($err);		
	print_r( 'failure on recv'.$errormsg.PHP_EOL);		
}

    socket_close($socket);

 

can anyone see the problem with this?

Link to comment
https://forums.phpfreaks.com/topic/168867-socket_read-unix-socket/
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.