How to keep alive Socket in php? On user command disconnect?
Senario 1:
Client=======Server
1. Connect send
--------------->
2. Ack Recv
<---------------
3. Echo/Primitive
--------------->
4. hh:mm minute
processing....
----------------
5. Status recv
<---------------
6. New command
---------------->
7. Close on request
---------------->
Code:
===============
// Send Raw data over TCP
$fp = fsockopen ('212.58.58.58',5400, $errno, $errstr, 30);
if (!$fp) {
// Error
} else {
// 1st primitive
fwrite($fp,$sends); //fixed
echo hex4str (fread ($fp,256)); //read for debug
// On recv data
// close this session on command not automatic.
fclose($fp);
}
Socket alive
Moderator: General Moderators
- vargadanis
- Forum Contributor
- Posts: 158
- Joined: Sun Jun 01, 2008 3:48 am
- Contact:
Re: Socket alive
before fclose, enter into an infinite loop: while(1){} and in that loop you can examine the commands that the server recieves from the client.
Next time, put your code into [ php ] tags so that we can read it easier..
Next time, put your code into [ php ] tags so that we can read it easier..