Socket alive

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
shamuntoha
Forum Newbie
Posts: 1
Joined: Thu Jul 10, 2008 9:29 am

Socket alive

Post by shamuntoha »

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);
}
User avatar
vargadanis
Forum Contributor
Posts: 158
Joined: Sun Jun 01, 2008 3:48 am
Contact:

Re: Socket alive

Post by vargadanis »

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..
Post Reply