473,785 Members | 2,209 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with Socket Receive

1 New Member
I have written an application for Receiving Stock Market Feed over a 2 Mbps Connection with Exchange with average incoming data of 800kbps.

The program works fine for sometime i.e. for an hour or so but then it throws SocketException Saying "An Operation on socket could not be performed because the system lacked sufficient buffer space ir because a queue was full".

But in my program i am receiving it very fast that on my internal LAN it works fine for 24 hours without any problem.

But in production environment it throws this exception after sometime i.e. 1.5 hours or 30 min or 15 min sometime. even i set buffer size 8k, 16k, 32k, 64k, 128k. still a problem.
Program is written in .Net Framework 1.1 using C#.

My ListenTCP code & Receive Data Code is like:

private void ListenTSTCPFeed ()
{
while(doRecieve TDFeed)
{
try
{
if(tdGatewaySoc ket.Poll(Config urations.POLL_T IMER,SelectMode .SelectRead) && tdGatewaySocket .Connected)
{
byte[] dataBuffer = ReceiveVarDataT weaked();
if(dataBuffer != null)
{
AddToQueue(data Buffer);
totalMessagesRe ceived++;
tdFeedProcessor .BeginInvoke(nu ll, null);
}
else
{
break;
}
}
else
{

#region Sleep Thread
Thread.Sleep(ne w TimeSpan(Net.Ta wasol.Config.Co nfigurations.ME SSAGES_PER_SECO ND));
#endregion
}
}
catch(NotSuppor tedException e)
{
//Start Fire Event OnDisConnection
TDConnectionSta tusEventArgs args = new TDConnectionSta tusEventArgs();
args.Message = "Unable to Connect with Reason:::: >> NotSupportedExc eption >>>"+e.Messag e;
OnDisConnection (args);
break;
//End Fire Event OnDisConnection
}
catch(SocketExc eption e)
{
//Start Fire Event OnDisConnection
TDConnectionSta tusEventArgs args = new TDConnectionSta tusEventArgs();
args.Message = "Unable to Connect with Reason:::: >> SocketException >>>"+e.Messag e;
OnDisConnection (args);
break;
//End Fire Event OnDisConnection
}
catch(ObjectDis posedException e)
{
//Start Fire Event OnDisConnection
TDConnectionSta tusEventArgs args = new TDConnectionSta tusEventArgs();
args.Message = "Unable to Connect with Reason:::: >> ObjectDisposedE xception >>>"+e.Messag e;
OnDisConnection (args);
break;
//End Fire Event OnDisConnection
}
}
Close(false);
}



{
int size;
byte[] datasize = new byte[4];
byte[] datasizeCopy = new byte[4];
byte[] data = new byte[0];
int i = 0;

#region Receive Bytes & Get Length of Data
while( i<4 )
{
try
{
i += tdGatewaySocket .Receive(datasi ze, i, 4-i, SocketFlags.Non e);
}
catch(Exception ex)
{
throw ex;
}
}

datasize.CopyTo (datasizeCopy, 0);

if(BitConverter .IsLittleEndian )
{
Array.Reverse(d atasize);
}

size = BitConverter.To Int32(datasize, 0);

try
{
data = new byte[size];
}
catch(Exception ome)
{
throw ome;
}
#endregion

#region Get Data Bytes
i = 0;
while(i < size)
{
try
{
int recv = tdGatewaySocket .Receive(data, i, size-i, SocketFlags.Non e);
if(recv == 0)
{
return null;
}
i += recv;
}
catch(Exception ex)
{
throw ex;
}
}
#endregion

byte[] msg = new byte[data.Length+4];
datasizeCopy.Co pyTo(msg, 0);
data.CopyTo(msg , 4);
DataReceived+=m sg.Length;
return msg;
}


Can anybody guide me about the problem.

Thanks.
Feb 12 '07 #1
0 1597

Sign in to post your reply or Sign up for a free account.

Similar topics

0
883
by: SK | last post by:
Hi, I am trying to send/receive data from a socket. The call to receive does not block . If I use sleep between send and receive things are ok. Here is the code - Socket m_socClient; //create a new client socket ... m_socClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
6
4126
by: roger beniot | last post by:
I have a program that launches multiple threads with a ThreadStart method like the following (using System.Net.Sockets.Socket for UDP packet transfers to a server): ThreadStart pseudo code: Connect Receive response Send Connect ACK
1
3973
by: Dan Kelley | last post by:
I have 2 projects - 1 Winform project that sends Udp messages using the UdpClient class when a button is clicked, and a Console application that listens for these Udp messages. If I try to use the UdpClient class to receive, it never works. The messages are never received (no exceptions). If I use a normal socket configured to listen for Udp messages, it works perfectly. Below is my sample code. It is only test code - I know the...
4
2352
by: Sa¹o Zagoranski | last post by:
Hi! I'm writing a simple 3D First person shooter game. It is a multiplayer game, where all the players connect to one server.
2
702
by: Droopy | last post by:
Hi, I try to implement a reusable socket class to send and receive data. It seems to work but I have 2 problems : 1) I rely on Socket.Available to detect that the connection is closed (no more data to expect). Sometimes, Socket.Available returns 0 but the other end of the connection did not close it ! 2) This class will be used by many other classes so I have to use the
1
1601
by: Hasan O | last post by:
hi , I have a problem with socket.send mesajlar = Encoding.ASCII.GetBytes("UGIR"); socketResultValue = socket.Send(mesajlar,0,mesajlar.Length, SocketFlags.None); socketResultValue = socket.Receive(mesajlar,0,mesajlar.Length,SocketFlags.None);
0
2060
by: Shoveler | last post by:
I've got an odd problem here that I've been beating my head on for days. I've written a class that uses a pre-established connection for communication, meaning I can use this class for a server or a client. After receiving a Socket that has been connected to a RemoteEP, it begins 2 threads by calling out Begin(). My Send Thread pauses until the class Parent wants to send data. Receive Thread keeps checking for incoming data. My...
2
5788
by: Daniel Lindberg | last post by:
Hi, im a beginner in C# and i just cant seem to get my udp broadcasting to work. What happens is that it just locks down on the Receive call and never gets any data. I have the code for the server who answers the broadcast, so i know that it sends a reply, but i cant figure out why my C# client cant receive it.. Any input on whats wrong with my code will be appreciated //My code...
2
5699
by: Rene Sørensen | last post by:
I'm using .NET 2.0 VS 2005 I'm creating a function that dos something similar to the. SmoApplication.EnumAvailableSqlServers() function. But for som resone I get an error or do i?. The problem is that the program just return from the function when it reach the recive part( reviced = socket.Receive(bytBuffer); ), below here you can se the code. I used eathereal to check the package that is send and reviced, that looks all fine. I do...
1
2251
by: Jean-Paul Calderone | last post by:
On Mon, 12 May 2008 08:34:07 -0700 (PDT), petr.poupa@gmail.com wrote: You cannot reconnect a socket. You need to create a new one for each connection. It's also almost certainly the case that the way you are receiving data is incorrect. There is no guarantee that you will get 2048 bytes from socket.recv(2048). It isn't even guaranteed that all the bytes written to the socket by the peer will be returned by such a call. Instead, you...
0
9646
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10350
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10097
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8983
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5386
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5518
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.