472,142 Members | 1,283 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

strange problems with Socket.Send/Socket.Receive

Hello everyone,

I'm having some odd problems with a little program I wrote for
sending/receiving bytes across the network.

I am using synchronous sockets, and it seems that when I send byte
after byte too fast, the packet gets lots somewhere (as odd as that
sounds).

Here's the sending code:

.....
try {
if (sHandler.Connected)
{
int cSent = 0;
while (cSent == 0)
{
cSent = sHandler.Send(byteSend, 0,
byteSend.Lenght, System.Net.Sockets.SocketFlags.None);
}

}
}
catch (SocketException se)
{
Debug.WriteLine(se.Message);
}
.....

The receiving code is basicly a thread that keeps on running untill
the socket is connected and reads 1 byte per byte. Since i'm using
blocking sockets that seems to work fine.

Simple enough, I use these functions to send chars over a TCP
connection.I read an array of bytes byte per byte and use the function
above to send byte per byte. From what I've tested, if I send too
fast, the receiver never gets all the data. If I would to put a small
delay, like Sleep(1) in there, then everything works fine.

I installed a network sniffer on each workstations I am testing this
code off and as I've said, when I send too fast (as in, no delay after
each byte) the network sniffer on the sender side shows the packet
with the data I'm trying to send, but the receiver's network sniffer
does not. If I put a delay in there, I can see the packet with the
data I'm sending on both sides. I've also tried using a cross-over
cable to remove any possible network interferences and the result is
still the same. As far as the sender is concerned, it sends the data,
and as far as the receiver is concerned, it never gets it.

Does anybody have any idea what's going on, because I'm flat out of
ideas?
Nov 16 '05 #1
1 2769
After a tad more testing, I have found out that my problem goes away
if I send the whole array of bytes in one .Send command, instead
sending it byte per byte.

Still, the behavior seems a bit odd to me?

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Robert A. van Ginkel | last post: by
5 posts views Thread by Terry | last post: by
2 posts views Thread by Nuno Magalhaes | last post: by
reply views Thread by ZR | last post: by
2 posts views Thread by djc | last post: by
6 posts views Thread by White Spirit | last post: by
9 posts views Thread by =?Utf-8?B?SG93YXJkIFNtaXRo?= | last post: by
reply views Thread by leo001 | last post: by

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.