Re: multiple tcp server and client execution with close problem



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 -


.



Relevant Pages

  • Re: Socket switch delay
    ... both at the client and at the server (and why ... would you set the send buffer size to zero on a non-overlapped ... One glaring error is your client does ... So when you use a single socket, ...
    (microsoft.public.win32.programmer.networks)
  • Re: Locking on async calls
    ... you must synchronize the entire SendMessage routine as an atomic ... operation to prevent mixed messages from being transmitted to the server. ... You are correct that read and write on the socket do not interfere with each ... If you want to handle multiple client connections from one server object ...
    (microsoft.public.dotnet.general)
  • Re: socket communication: socket doesnt connect
    ... Microsoft MVP, MCSD ... As far as your server code goes, ... accept the listening socket. ... Client client = new Client; ...
    (microsoft.public.vc.language)
  • Re: TCP server stop receiving new connections
    ... reset the event mask of your listening socket each time you ... I have a strange problem in my class library used by all our client ... server applications. ... incomming connections, but keeps current connections. ...
    (microsoft.public.win32.programmer.networks)
  • Re: Design issue with WinSock/GetQueuedCompletionStatus
    ... delegate that to a shutdown routine called after all worker threads ... The application I've created is a server accepting connections on a few ... different TCP/IP ports and then lets the client run different commands. ... a TCP/IP socket can be closed for 2 different reasons: ...
    (microsoft.public.win32.programmer.networks)