Use a Server or Client Socket?

From: Date: Sat, 07 Feb 2004 08:06:21 +0000
Subject: Use a Server or Client Socket?
Groups: php.general 
Request: Send a blank email to php-general+get-177087@lists.php.net to get a copy of this message
Hi all, I have this situation now that requires socket programming. But I am not sure how to realise the requirements in programming whether as a client or server The requirement is like this. I have to connect to an external server constantly to listen for incoming data. How can I make sure that the connection is there all the time? Upon receiving the message, I will have to response back an acknowledgement that the message is received. I can also send data to the server. From my requirements, I understand that there will only be one connection. Therefore the data exchange need not be in sequence. Currently, what I have is a server programmed using the socket library. Server logic : socket_create socket_bind socket_listen while(true) { socket_select if(new connection) { add to connections array } else { if(can read) { read incoming response back } else { //error or connection close if(error) { print error } else { print connection close remove from connections array } } } } I am planning to include a check somewhere in the codes for maintaining the connection between my server and the other server. Where should I place it? Also, I need to initiate a connection to the external server and then listen. Where should this piece of code be insert at? Is this the right approach? Or I am over killing by writing a server if this can be handle in easier manner. Hope that I have been clear in the above. Thanks for helping Ai Leen

« previous php.general (#177087) next »