Hi Tan,

If you are connecting to another server you are using a client socket you do not need to make a server socket. If you need to listen for connections make use of a server socket. To give you an example your browser makes use of client sockets while apache makes use of server sockets. That is an over simplified view of things but hope it helps you understand things better.

Generally working with client sockets is easier.

best regards
raditha


Tan Ai Leen wrote:


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





--
Raditha Dissanayake.
------------------------------------------------------------------------
http://www.radinks.com/sftp/         | http://www.raditha.com/megaupload
Lean and mean Secure FTP applet with | Mega Upload - PHP file uploader
Graphical User Inteface. Just 150 KB | with progress bar.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to