473,405 Members | 2,185 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,405 software developers and data experts.

Problem with Socket Receive

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(doRecieveTDFeed)
{
try
{
if(tdGatewaySocket.Poll(Configurations.POLL_TIMER, SelectMode.SelectRead) && tdGatewaySocket.Connected)
{
byte[] dataBuffer = ReceiveVarDataTweaked();
if(dataBuffer != null)
{
AddToQueue(dataBuffer);
totalMessagesReceived++;
tdFeedProcessor.BeginInvoke(null, null);
}
else
{
break;
}
}
else
{

#region Sleep Thread
Thread.Sleep(new TimeSpan(Net.Tawasol.Config.Configurations.MESSAGE S_PER_SECOND));
#endregion
}
}
catch(NotSupportedException e)
{
//Start Fire Event OnDisConnection
TDConnectionStatusEventArgs args = new TDConnectionStatusEventArgs();
args.Message = "Unable to Connect with Reason:::: >> NotSupportedException >>>"+e.Message;
OnDisConnection(args);
break;
//End Fire Event OnDisConnection
}
catch(SocketException e)
{
//Start Fire Event OnDisConnection
TDConnectionStatusEventArgs args = new TDConnectionStatusEventArgs();
args.Message = "Unable to Connect with Reason:::: >> SocketException >>>"+e.Message;
OnDisConnection(args);
break;
//End Fire Event OnDisConnection
}
catch(ObjectDisposedException e)
{
//Start Fire Event OnDisConnection
TDConnectionStatusEventArgs args = new TDConnectionStatusEventArgs();
args.Message = "Unable to Connect with Reason:::: >> ObjectDisposedException >>>"+e.Message;
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(datasize, i, 4-i, SocketFlags.None);
}
catch(Exception ex)
{
throw ex;
}
}

datasize.CopyTo(datasizeCopy, 0);

if(BitConverter.IsLittleEndian)
{
Array.Reverse(datasize);
}

size = BitConverter.ToInt32(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.None);
if(recv == 0)
{
return null;
}
i += recv;
}
catch(Exception ex)
{
throw ex;
}
}
#endregion

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


Can anybody guide me about the problem.

Thanks.
Feb 12 '07 #1
0 1581

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

Similar topics

0
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;...
6
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: ...
1
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...
4
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
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...
1
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 =...
0
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...
2
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...
2
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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,...
0
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,...
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.