Re: multiple tcp server and client execution with close problem
- From: "Ray" <alienatsf@xxxxxxxxx>
- Date: 19 Mar 2007 13:55:34 -0700
Barry,
Sorry for the confusion. Ignore the loop for accept(). It's useless
for accept() after settting socket to blocking mode.
Okay, my scenario is like this:
server side:
main:
loop multiple times
{
system("./MyServer");
}
In the MyServer executable code:
socket
ioctl blocking
bind
listen
accept
recv something
recv data
send other things
close
Client side:
loop multipe times
{
socket
ioctl blocking
while loop to connect
send something
send data
shutdown send
recv other things
close
}
execute main to run server 3 times:
../main 3
waiting for client
execute client to run 3 times:
../client 3
so for the first loop run, main receive data from client and send back
data to client, and main close the server socket and reopen another
socket for waiting the next incoming client connect() call. meanwhile
upon finishing sending data to server and receiving data back from
server, client close socket and open another socket to connect to
server.
So here comes the problem, in the 2nd loop run, the main (that runs
the server) stops there waiting for the new client while client also
stops there waiting for the new server to connect to.
Any idea why?
Btw, I run both client and server on the same machine using 127.0.0.1
loopback address.
My code works smoothly in my Suse Linux 10.2, but has this problem on
Mac OS X. but Mac OS X is based on Unix. What is the problem?
Thanks
On Mar 18, 9:16 am, Barry Margolin <bar...@xxxxxxxxxxxx> wrote:
In article <1174182884.213328.185...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
"Ray" <aliena...@xxxxxxxxx> wrote:
On Mar 17, 3:30 pm, Barry Margolin <bar...@xxxxxxxxxxxx> wrote:
In article <1174117981.427306.6...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
"Ray" <aliena...@xxxxxxxxx> wrote:
Hi, I have a tcp/ipserverand client program runs like this:
serverside:
main:
loopmultipletimes
{
system("./MyServer");
}
In the MyServer executable code:
socket
ioctl blocking
bind
listen
while loop to accept
recv something
recv data
send other things
close
Client side:
loop multipe times
{
socket
ioctl blocking
while loop to connect
send something
send data
shutdown send
recv other things
close
}
The problem it has is after first finishing first loop with successful
operation on bothserverand client,serveris waiting for client, and
Why is theserverstill waiting for the client? When the client does
shutdown(fd, SHUT_WR), theserverwill read EOF, and it should stop
trying to read from the socket.
client is waiting to successfully connect toserveragain. So both are
waiting without doing anything. This is due to the close function
cannot complete closing the socket level descriptor for client side
detected by perror (maybeserverside as well). Is there a way to get
around this problem? I have read the unix faq and search thru
comp.unix.programmer, but found no better solution for my situation
( I tried with or without shutdown at the end, also tried
SO_REUSEADDR, SO_LINGER with no luck).
Theservercode is a stand-alone executable. It has to be spawned by
function system formultipletimes. I cannot get theserveron all the
time then. So I decided to connect toserverformultipletimes from
client side. Is there a way in algorithm to better solve this
situation?
The server is still waiting because there is another function calling
system() to execute server again after its previous use. It's like
when both the server and client finish transmission, the server turns
off power, then restart again. while the client never turns off but
doing a loop to reconnect to the server again for the next
transmission. The server behaves like this because the server app is
a given executable for other major process, like Monte Carlo process.
The tcp/ip is for updating data for that process.
I'm confused about which loop is hanging. Your description shows a loop
calling system("./MyServer"), but there's also a loop INSIDE MyServer
that you described with "while loop to accept".
So are you having problems with the accept loop, or just when the server
restarts with system()?
--
Barry Margolin, bar...@xxxxxxxxxxxx
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***- Hide quoted text -
- Show quoted text -
.
- Follow-Ups:
- Re: multiple tcp server and client execution with close problem
- From: Barry Margolin
- Re: multiple tcp server and client execution with close problem
- References:
- multiple tcp server and client execution with close problem
- From: Ray
- Re: multiple tcp server and client execution with close problem
- From: Barry Margolin
- Re: multiple tcp server and client execution with close problem
- From: Ray
- Re: multiple tcp server and client execution with close problem
- From: Barry Margolin
- multiple tcp server and client execution with close problem
- Prev by Date: Re: Protocols to exchange messages via a socket
- Next by Date: wayward system() call errors
- Previous by thread: Re: multiple tcp server and client execution with close problem
- Next by thread: Re: multiple tcp server and client execution with close problem
- Index(es):
Relevant Pages
|