473,394 Members | 4,011 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,394 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

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)

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
Nov 16 '05 #1
1 2869
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Robert A. van Ginkel | last post by:
Hello Fellow Developer, I use the System.Net.Sockets to send/receive data (no tcpclient/tcplistener), I made a receivethread in my wrapper, the receivethread loops/sleeps while waiting for data...
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: ...
by: Terry | last post by:
It's my understanding of UDP sockets that if there is a thread blocked on a "recvFrom()" call and other thread sends a UDP packet to some address, that if the machine on the other end isn't up,...
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: ZR | last post by:
I am writing two applications which needs to (among other things) communicate through network, so one of them is a client and the other one is a server. I have used asynchronous socket examples...
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: White Spirit | last post by:
I have the following code to send a packet to a remote socket and receive a response in return: System.Net.Sockets.Socket locSocket = new System.Net.Sockets.Socket (AddressFamily.InterNetwork,...
by: =?Utf-8?B?SG93YXJkIFNtaXRo?= | last post by:
I am using VC++ 6.0 (with SP5 installed). When using WinXP this is with SP2 installed. I am developing an instrumentation system comprising a set of networked PCs connected using TCP/IP TCP links....
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: 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: 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: 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,...
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...
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...
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...

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.