Reading socket response with php does not work -


code:

$str = "example"; $socket = socket_create(af_inet, sock_stream, sol_tcp);           socket_connect($socket, "127.0.0.1", "2107");           socket_listen($socket);           socket_write($socket, $str, strlen($str)); $resp   = socket_read($socket, strlen($str), php_read_normal); echo $resp; 

without socket_read works perfect , $str value in console application output (response console application success). far add socket_read script loading , hanging up. , not see $str value in console application although should done (with socket_write) before socket listining response. there notify in console application connection has been established hanging - without stream_read -> perfect.

any ideas?

just looking @ of old code did seemed work:

//for connecting $serverconn = @stream_socket_client("tcp://127.0.0.1:2107", $errno, $errstr, 1);  //for sending fwrite($serverconn, $message);   //for reading $response = stream_get_contents($serverconn); 

this assumes have service running on port.

otherwise perhaps try using socket_bind instead of socket_connect


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -