Hi, I've got a C# client/service application using a Socket object to
communicate. I have a socket bug that I can't solve without
kludged-code. Does anyone know a more elegant solutions? Is this a
known bug with the .NET Socket object?
Under high stress data sending, I occasionally receive duplicate data
on the server which really throws a wrench into the system. The
duplicate data I receive is always part of the tail end of the last
message sent.
Example:
Message 1: FirstMessage
Message 2: SecondMessage
Message 3: ssage (DUPLICATE BUG!)
Message 4: FourthMessage
I need to eliminate this problem. The only solution I have that works
is to add a Thread.Sleep(10) immediately after Socket.Send(buffer). If
I add that sleep, it works perfectly every time.
I have tried using a NetworkStream instead of a Socket, and I have
tried BeginSend/EndSend and they all demonstrate the exact same
problem.
This only happens when I am sending message very fast in a loop such
as:
for (int i=0; i < 1000; i++)
{
_socket.Send(buffer);
}
or
for (int i=0; i < 1000; i++)
{
// Async way
IAsyncResult asyncSend = _socket.BeginSend(regPackage, 0,
regPackage.Length, System.Net.Sockets.SocketFlags.None, null, null);
_socket.EndSend(asyncSend);
}
or
for (int i=0; i < 1000; i++)
{
SendData(_socket, regPackage);
}
public int SendData(TSSocket s, byte[] data)
{
int total = 0;
int size = data.Length;
int dataleft = size;
int sent;
while (total < size)
{
sent = s.Send(data, total, dataleft,
System.Net.Sockets.SocketFlags.None);
total += sent;
dataleft -= sent;
}
return total;
}
Again, the only solution that has worked for me is adding a
Thread.Sleep(10), or some other code that keeps the processor busy so
that the Send has time complete. I tried shorter wait times, but 1 or
2 doesn't give enough time, so I played it safer and choose 10.
The is a sample of how I've currently got it working:
for (int i=0; i < 1000; i++)
{
SendData(_socket, buffer);
Thread.Sleep(10);
}
HELP! 2 2685
Not sure, but are you trying to send the same buffer multiple times?
--
William Stacey [MVP]
"Matt" <ma*******@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com... Hi, I've got a C# client/service application using a Socket object to communicate. I have a socket bug that I can't solve without kludged-code. Does anyone know a more elegant solutions? Is this a known bug with the .NET Socket object?
Under high stress data sending, I occasionally receive duplicate data on the server which really throws a wrench into the system. The duplicate data I receive is always part of the tail end of the last message sent.
Example: Message 1: FirstMessage Message 2: SecondMessage Message 3: ssage (DUPLICATE BUG!) Message 4: FourthMessage
I need to eliminate this problem. The only solution I have that works is to add a Thread.Sleep(10) immediately after Socket.Send(buffer). If I add that sleep, it works perfectly every time.
I have tried using a NetworkStream instead of a Socket, and I have tried BeginSend/EndSend and they all demonstrate the exact same problem.
This only happens when I am sending message very fast in a loop such as:
for (int i=0; i < 1000; i++) { _socket.Send(buffer); }
or
for (int i=0; i < 1000; i++) { // Async way IAsyncResult asyncSend = _socket.BeginSend(regPackage, 0, regPackage.Length, System.Net.Sockets.SocketFlags.None, null, null); _socket.EndSend(asyncSend); }
or
for (int i=0; i < 1000; i++) { SendData(_socket, regPackage); }
public int SendData(TSSocket s, byte[] data) { int total = 0; int size = data.Length; int dataleft = size; int sent; while (total < size) { sent = s.Send(data, total, dataleft, System.Net.Sockets.SocketFlags.None); total += sent; dataleft -= sent; } return total; }
Again, the only solution that has worked for me is adding a Thread.Sleep(10), or some other code that keeps the processor busy so that the Send has time complete. I tried shorter wait times, but 1 or 2 doesn't give enough time, so I played it safer and choose 10.
The is a sample of how I've currently got it working:
for (int i=0; i < 1000; i++) { SendData(_socket, buffer); Thread.Sleep(10); }
HELP!
I'm really not trying to send the same buffer multiple times, that's
just an example of what I mean. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Chris Tanger |
last post by:
Context:
C#
System.Net.Sockets
Socket created with constructor prarmeters Internetwork, Stream and TCP
everything else is left at the default parameters and options except linger
may be changed...
|
by: Nuno Magalhaes |
last post by:
I've got a simple problem I guess. How do I know when a connection is
terminated without losing any data?
I do something like the code below, but sometimes between
socket.Receive and socket.Send...
|
by: djc |
last post by:
I read a network programming book (based on framework 1.1) which indicated
that you should 'never' use the RecieveTimeout or the SendTimeout 'socket
options' on TCP sockets or you may loose data. I...
|
by: hazz |
last post by:
smtpClient.Send(message)
is causing me problems as per specifics in the trace below. Email is sent
but not without this error typically upon sending the second email, but
sometimes when running...
|
by: BuddyWork |
last post by:
Hello,
Could someone please explain why the Socket.Send is slow to send to the same
process it sending from. Eg. Process1 calls Socket.Send which sends to the
same IP address and port, the...
|
by: Buddy Home |
last post by:
There is two examples of code.
Example 1. Send and Receive within the same process. Put this code in a
console app called SendAndReceive and run the code.
using System;
using...
|
by: ahlongxp |
last post by:
Hi, everyone,
I'm implementing a simple client/server protocol.
Now I've got a situation:
client will send server command,header paires and optionally body.
server checks headers and decides...
|
by: manasap |
last post by:
Hi all!
I've written a server and a client application using asynchronous sockets.The client sends data packets for every 7 seconds.The server receives the packets.
This process proceeds...
|
by: Ali Hamad |
last post by:
Hello All :
A socket question from a networking newbie. I need to create
a server that:
1) receive a message from client.
2) check that message and response to it.
3) the client get the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
| |