Need advise on sockets

A

abhi147

Hi ,

I have a program which has 1 client and 4 servers . Client
sends messages(every second) to all these 4 servers and recieves a
response from these servers . It has load balaning and failover logic
in it .
Now my question is , is it a good practice to connect to these servers
outside the while loop or should I connect these inside the loop(so
that client connect to server everytime a message is being sent ) ..
Wouldn't connecting and closing the socket every second be a load on
the system ?

Thanks !
 
K

Keith Thompson

I have a program which has 1 client and 4 servers . Client
sends messages(every second) to all these 4 servers and recieves a
response from these servers . It has load balaning and failover logic
in it .
Now my question is , is it a good practice to connect to these servers
outside the while loop or should I connect these inside the loop(so
that client connect to server everytime a message is being sent ) ..
Wouldn't connecting and closing the socket every second be a load on
the system ?

This isn't a C question.

Try a newsgroup specific to your system (comp.unix.programmer?).
 
K

kondal

Hi ,

I have a program which has 1 client and 4 servers . Client
sends messages(every second) to all these 4 servers and recieves a
response from these servers . It has load balaning and failover logic
in it .
Now my question is , is it a good practice to connect to these servers
outside the while loop or should I connect these inside the loop(so
that client connect to server everytime a message is being sent ) ..
Wouldn't connecting and closing the socket every second be a load on
the system ?

Thanks !

connecting and closing the socket every second creates a lot of load on
the system. From the explanation, I see that you are implementing the
heartbeat operations on the servers.

Generally when the client comes up it creates the connections for the
heartbeat to the servers and sends the packets using the timer handler
for every second. The responces are not caught in the timer handler,
but in the main loop where the select/poll is used. Reason, the reply
times may vary and exceed the time length (1 sec).

-kondal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top