473,399 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Async TCP Socket Problem with bells on

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/de...ketexample.asp

Client:

http://msdn.microsoft.com/library/de...ketexample.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.

Aug 4 '06 #1
2 1980
"pigeonrandle" <pi**********@hotmail.comwrote:
I'm using the following example code from MS (perhaps i am doomed from
the outset!) ..
http://msdn.microsoft.com/library/de...ketexample.asp
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

--
http://barrkel.blogspot.com/
Aug 4 '06 #2
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 Kelly wrote:
"pigeonrandle" <pi**********@hotmail.comwrote:
I'm using the following example code from MS (perhaps i am doomed from
the outset!) ..
http://msdn.microsoft.com/library/de...ketexample.asp
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

--
http://barrkel.blogspot.com/
Aug 4 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Joshua Coady | last post by:
I am writing a class that includes several async methods following the BeginXxx, EndXxx pattern. Some of these methods will call methods in the framework such as Stream.Read or Socket.Send. Do I...
2
by: dream machine | last post by:
Hi all , with BegeinReceive I can build async method of Socket Class that Receive the data from the Socket Client . My question is , if I have this code that create 3 Receive Async Call : ...
1
by: Mark Smith | last post by:
Hi , Is it possible in .Net to define a async timer callback. What I am wanting to do is declare a time-out condition that gets executed should the something timeout. The reason I want to do...
8
by: MuZZy | last post by:
Hi, Could someone pls help me here: If i use async sockets in the separate thread like this: void ThreadFunction() { ..... 1. MySocket.BeginAccept(AsyncCallBack(OnConnectRequest),...
6
by: Shak | last post by:
Hi all, Three questions really: 1) The async call to the networkstream's endread() (or even endxxx() in general) blocks. Async calls are made on the threadpool - aren't we advised not to...
7
by: Shak | last post by:
Hi all, I'm trying to write a thread-safe async method to send a message of the form (type)(contents). My model is as follows: private void SendMessage(int type, string message) { //lets...
11
by: atlaste | last post by:
Hi, In an attempt to create a full-blown webcrawler I've found myself writing a wrapper around the Socket class in an attempt to make it completely async, supporting timeouts and some scheduling...
10
by: Frankie | last post by:
It appears that System.Random would provide an acceptable means through which to generate a unique value used to identify multiple/concurrent asynchronous tasks. The usage of the value under...
1
by: Ryan Liu | last post by:
Hi, I have a 100 clients/ one server application, use ugly one thread pre client approach. And both side user sync I/O. I frequently see the error on server side(client side code is same, but...
10
by: ColoradoGeiger | last post by:
I have a fairly standard server application that I am using asynchronous socket calls to make connections, send and receive data, and all of that jazz. No blocking methods was my goal in writing...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.