Hi Raditha,

Thanks, I have a better idea of how to write the codes. But I wonder, to check that the connection to the external server is on, where should I place the code? I need to do this every 10 minutes. If the connection is dropped, I have to reconnect. Where should I place this check? If I place it in the while(true) loop, I will be checking every few miliseconds rite? That will be too frequent. What about in another script? Will I be able to check that the connection is on?

Regards,
Ai Leen

Raditha Dissanayake wrote:
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






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



Reply via email to