Async TCP Socket Problem with bells on

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.
 
B

Barry Kelly

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
 
P

pigeonrandle

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
 

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

Top