Async TCP Socket Problem with bells on

  • Thread starter Thread starter pigeonrandle
  • Start date Start date
P

pigeonrandle

Hi,
I'm looking a TCP guru, so i apologise for any campanologists i may
have attracted by my title.

I'm using the following example code from MS (perhaps i am doomed from
the outset!) ..

Server:

http://msdn.microsoft.com/library/d...html/cpconnon-blockingserversocketexample.asp

Client:

http://msdn.microsoft.com/library/d...html/cpconnon-blockingclientsocketexample.asp

both can just be pasted over the generated code of a new console
application.

So i run the server, then run the client and get the expected result.

Now i change just the client Main() to:

public static int Main(String[] args)
{
Console.ReadLine();
StartClient();
Console.ReadLine();
StartClient();
return 0;
}

and when i press return for the second time, i get some ridiculous
error.

BUT, if i have two of the clients running at the same time on the same
(or different machines), they both work once, and then also throw a
ridiculous error.

I would really, really, really appreciate some help on this as it is
driving me nuts!
Thanks for reading,
James Randle.
 
pigeonrandle said:
I'm using the following example code from MS (perhaps i am doomed from
the outset!) ..

Now i change just the client Main() to:

public static int Main(String[] args)
{
Console.ReadLine();
StartClient();
Console.ReadLine();
StartClient();
return 0;
}

StartClient() relies on a bunch of events (connectDone etc) being
cleared, but after one execution they're set and thus won't block.
StartClient() is thus good for only one run, unless you modify it to
reset the events.
and when i press return for the second time, i get some ridiculous
error.

I notice you didn't mention the error.

-- Barry
 
Barry,
I love you! Changing the client Main() function to:

public static int Main(String[] args)
{
Console.ReadLine();
StartClient();
connectDone.Set();
receiveDone.Reset();
sendDone.Reset();
Console.ReadLine();
StartClient();
return 0;
}

has indeed solved the problem. This 'type of problem' has had me
stumped for ages (doh), like days dammit.

All hail Barry. Seriously though thankyou VERY much,
James.

Barry said:
pigeonrandle said:
I'm using the following example code from MS (perhaps i am doomed from
the outset!) ..

Now i change just the client Main() to:

public static int Main(String[] args)
{
Console.ReadLine();
StartClient();
Console.ReadLine();
StartClient();
return 0;
}

StartClient() relies on a bunch of events (connectDone etc) being
cleared, but after one execution they're set and thus won't block.
StartClient() is thus good for only one run, unless you modify it to
reset the events.
and when i press return for the second time, i get some ridiculous
error.

I notice you didn't mention the error.

-- Barry
 
Back
Top