1

I bind with a socket as follows:

<?
// set some variables
$host = "x.x.x.x";
$port = 1234;
// don't timeout!
set_time_limit(0);
// create socket
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create
socket\n");
// bind socket to port
$result = socket_bind($socket, $host, $port) or die("Could not bind to
socket\n");
?>

Now how do I read strings coming from the socket and store it in a variable? The socket has collection of strings in the following format: 12;3p6;4p

where p is the terminating character for each set of a;b values Thank you

1 Answer 1

3

You should use

socket_read()

to read the incoming data from the socket. Here is a nice tutorial on the socket programming in php.

http://www.devshed.com/c/a/PHP/Socket-Programming-With-PHP/

On a sidenote, PHP is not a very suitable language for socket programming and use it only if its absolutely necessary.

Sign up to request clarification or add additional context in comments.

1 Comment

will socket_read also help me to read a live stream data from socket server? Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.