473,503 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with C# asynchronous sockets

Somewhere around 500 connections when calls (BeginSend calls) are
arround 108,752 and total bytes sent are around 9,496,399 bytes - send
callbacks (EndSend) stop coming in C# asynchronous sockets.

I'm counting how many BeginSend are issued and how many EndSend are
received, and somewhere around 500 connections send callbacks stop
coming even when the count for BeginSend shows that there are pending
sends in the system.

Here is the code:

private void SendData(OStateObject so, string sData)
{
byteData = Encoding.ASCII.GetBytes(sData);

try
{
so.socket.BeginSend(byteData, 0, byteData.Length, 0, new
AsyncCallback(SendCallback), so);
PendingSends = Interlocked.Increment(ref PendingSends);
}
catch(System.ObjectDisposedException)
{
}
catch (SocketException e)
{
DestoryStateObject(so);

}
catch (Exception e)
{
DestoryStateObject(so);
}
}

private void SendCallback(IAsyncResult ar)
{
OStateObject so = (OStateObject)ar.AsyncState;

try
{
MaxSendBytes += so.socket.EndSend(ar);
PendingSends = Interlocked.Decrement(ref PendingSends);
}
catch (SocketException e)
{
PendingSends = Interlocked.Decrement(ref PendingSends);
DestoryStateObject(so);
}
catch (Exception e)
{
PendingSends = Interlocked.Decrement(ref PendingSends);
DestoryStateObject(so);
}
}

Here is code from the timer which executes this code every 2 second.

if (ArrayListConnectedSockets.Count >= 500)
{
//"TBGSends" is a global variable to keep track of maximum number of
sends
string bgMsg = "TestData :ghghe ghghghghgh whrerhehrehreh
hthththththththht eherehherehhee ghghe ghghghghgh whrerhehrehreh
hthththththththht eherehherehhee\n";
OStateObject so;
for (int i=0; i<ArrayListConnectedSockets.Count || TBGSends <= 150000;
i++)
{
so = (OStateObject)ArrayListConnectedSockets[i];
SendData(so, bgMsg);
TBGSends++;
}

if (TBGSends >= 150000) TimerBG.Stop();
}
I'm restricting maximum number of connection to 1000 after reaching
this limit server shuts down every new connection.

Maximum a user can send 5 times within a second. If there are 1024
users connected to each other than the server would make 1047552 send
calls if all users send something to each other with in few seconds. 1
or 2 seconds delay doesn't matter but the server jams during the
communication.

Why the server is jamming and anyway to solve this problem in C#?

Nov 17 '05 #1
0 1524

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

Similar topics

3
5099
by: David | last post by:
Hi, Ive been trying to work this out for the past 2 days now and im not getting anywhere fast. The problem i have is that i am using Asynchronous sockets to create a Socket Client library....
3
2468
by: Matthew King | last post by:
Hi all I've written a asynchronous socket client class, but i've found that in order to consume it I have to use events, and cannot simply for example SocketClient client = new...
9
8655
by: Michael Lindsey | last post by:
I need to write a server app to send images to client GUIs that are outside of the server's domain. The client will have the file system path to the image but can not access the file system. I am...
0
339
by: Kruz | last post by:
Somewhere around 500 connections when calls (BeginSend calls) are arround 108,752 and total bytes sent are around 9,496,399 bytes - send callbacks (EndSend) stop coming in C# asynchronous sockets....
1
3356
by: Assaf Shemesh | last post by:
Hi, I'm having a problem with asynchronous HttpWebRequest. It's a simple http client-server. For most of my users it works fine. However, some of them get the exception: ...
1
1554
by: DaTurk | last post by:
Hi, Lets see, for arguements sake lets just say that I have a server, which site waiting to receive connections, it then has an array of sockets that are connected to it. It's receiving all of...
4
3590
by: Engineerik | last post by:
I am trying to create a socket server which will listen for connections from multiple clients and call subroutines in a Fortran DLL and pass the results back to the client. The asynchronous socket...
2
3411
by: Nicolas Le Gland | last post by:
Hello everyone here. This is my first post in this newsgroup, I hope I won't be to much off-topic. Feel free to redirect me to any better group. I am getting strange timing issues when...
0
1252
by: alan | last post by:
Hello all, I'd like to ask recommendations about a "good" generic asynchronous I/O library for C++. By generic I mean, something I can use even on files, stdin/stdout, and sockets. I've seen...
0
7076
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
7274
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6984
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
7453
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
5576
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5005
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...
0
3162
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1507
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
732
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.