473,698 Members | 2,503 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TCPClient Losing Data

Long story short: I am misusing the TCPClient class. I am sending
400-500 byte messages, and data is being lost.

How can the TCPClient class be misused to lose data?

Background notes:
-I know the TCP protocol doesn't lose data. Don't tell me that. I am
educated.
-I am buffering all data being received before checking for messages
and reading them, so don't tell me this either. I have quite a spiffy
message system tried and proven. It's just these large chunks of data
screwing me over.
-I am using BeginRead/EndRead to receive my data.
-I am using a huge receive and send buffers, this simply can't be the
problem unless I'm misusing them.
-Changing the receive buffer does affect how long before it breaks.
However, how many bytes it takes before it breaks is inconsistent,
even with the same bytes being sent each time.
-Through tedious byte by byte comparison, it appears that "older"
bytes are being overwritten with newer, more recently received bytes.
By comparing the sent and received bytes, there is a gap of missing
bytes in the center. It's as if the buffer is too small, though, 3
megabytes for 500 bytes should be plenty of space... plus, the EndRead
function should be called anyway!
-I have read that the ReceiveTimeOut property should be set to
something else than zero to ensure no loss of data. Why is this? What
if it ran out of time and no bytes were received? Wouldn't this return
a length of zero bytes and appear to be a disconnection?
-Where it breaks is inconsistent. I can do the same login procedure
time and time again, and it will break at different places.

-Kinda unrelated: What is the State argument for in the BeginRead
function!? MSDN says you should "at the minimum pass the NetworkStream
class." One example passes the TCPClient class. Another example passes
seemingly random things (the form, a button on a toolstrip). The
example I based mine off of passed nothing/null.

Worst case scenario: can someone show me an example (I learn best by
examples honestly) that features a little program that can send and
receive using the TCPClient class many complete 400-500 byte messages?

Thanks; I'm sorry for the ugliness of this post. I lost my full,
detailed, nicely written post.

Jun 28 '07 #1
2 2284
Long story short: I am misusing the TCPClient class. I am sending
400-500 byte messages, and data is being lost.
-I am using BeginRead/EndRead to receive my data.
Some time ago, I gave up on BeginWhatever/EndWhatever owing to, well, I
don't know exactly what, but I had troubles that would not go away. Pressed
for time, I implemented what I needed with synchronous methods and I launched
a thread to achieve asynchronous operations. In some cases, I launched one
thread per use, and in other cases, I used one persistent thread with a queue
for batching. I never looked back, and I am a happy camper.

My suggestion is to try a test that isolates the problem to Begin/End.
Would it be much work to comment out these calls and replace them with their
synchronous counterparts? Not too much work I hope. Then run a stress test
to see if you lose data. Hopefully, you will continue to lose data, and
further fault isolation should be a snap because of the simpler single thread
setting. But my guess is that your data loss problems will go away. Now you
will have good news (you have a working model and a partly isolated fault in
the original design) and bad news (you don't have the answer to your original
question). What happens next is up to you.

I suspect you may find my response unsatisfying - sorry about that. We all
get set in our ways using techniques we like and trust and avoiding others.
I neither like nor trust the begin/end .net approach to asynchronous
operations. Too complicated, too quirky, too much going on under the
covers, and that is why I responded. Good luck on what sounds like a
challenging problem.

Jun 28 '07 #2
On Jun 28, 6:29 pm, DrZoop <DrZ...@gmail.c omwrote:

<snip>
I will copy and paste my post on another forum (I have to post in
three places minimum or else it will take ages (or forever) for me to
get help on my problem). It contains the code, super commented, along
with some further details.
<snip>

It's got lots of comments, but:
1) It contains code we should apparently ignore. It's worth getting
rid of such code.
2) It's not complete - we can't run it and see the problem.

The best way to get help - one which almost always works, in my
experience, is to post a short but *complete* program which
demonstrates the problem. This should:

1) Compile as written (preferably with no need to create a Visual
Studio project etc)
2) Only contain the necessary code (console apps tend to be simpler
than GUI apps)
3) Show what goes wrong

At that point it's much easier to reproduce the issue and help you.

See http://pobox.com/~skeet/csharp/complete.html for more information.

Jon

Jun 29 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
9095
by: Daniel | last post by:
TcpClient close() method socket leak when i use TcpClient to open a connection, send data and close the TcpClient with myTcpClientInstance.Close(); it takes 60 seconds for the actual socket on the client machine to close per my network app the computer fills up w/ thousands of these :0 TCP foobox:8888 localhost:2188 TIME_WAIT :0 TCP foobox:8888 localhost:2189 TIME_WAIT :0 TCP foobox:8888 localhost:2190 TIME_WAIT
3
3047
by: מורדי | last post by:
Hi, I'm writing a client/server application in which the client send a series of screenshots to the server to be saved using the tcpclient. in most cases the first screenshot is transmitted ok and arrives at the server but from after that i only a couple of KB from the start of the file which cases the picture to display only the very top (of the screen). All the pictures are saved at the client side before sent to the server and they...
3
28645
by: Ricardo Quintanilla | last post by:
i had a problem whom i do not know how to explain. i was using a TcpClient (System.Net.Sockets.TcpClient) object to send and receive data to an AS400 socket. Two months ago it started to work slowly, about 4 seconds between send and receive. In our production environment with hundreds of transactions it was truly costly. a while ago i changed de TcpClient object. Now i am using a Socket (System.Net.Sockets.Socket) object and it...
2
3204
by: Noozer | last post by:
Hi! Trying to get my head around working with network connectivity in VB.Net. I've gotten a fairly decent control based on the sample in the 101VBSamples available from Microsoft.What I'm having problems with is the GetStream.BeginRead method. Problem is that it's all one way... My application connects and is able to send data, but I don't have much in the way to provide realtime data back from my control Is GetStrem.BeginRead method...
1
4533
by: hamil | last post by:
I am having trouble using the TcpListener and TcpClient classes. At the end of this post is server code that runs, and a class whose purpose is described below. I need to know when the client closes the connection so I can exit my listener code. Here is what I have tried. First I asked MSDN and they said..
1
2247
by: Frank | last post by:
I wonder if anyone could give me a suggestion on how to best handle this scenario. I wish to have an aspx page contact a server and receive messages. Initially, a login messge is sent, then after being validated, a second message is sent which contains data to complete a stock market trade. The server then should respond not only once, but with several return messages. So far all I have found are examples that send, receive, and...
0
1431
by: zhangke007 | last post by:
Hello, everyone, Currently, I have an simple serial communication application using the serialnet.dll tool from Franson company. What this application does is to read the data through the com port in my windows ce 5 based wearable computer. The data is sent from a PIC microcontroller through the RS232 protocol. The scenario is like whenever you press a button, my PIC will detect the trigger and then send a single data through RS232...
6
3586
by: Bjoern Schliessmann | last post by:
Hello, I'm currently trying to implement a simulation program with Kamaelia and need a reliable TCP connection to a data server. From Twisted, I know that a method is called if the connection fails by whatever reason. I tried to get the same results with Kamaelia's TCPClient component. If I start up the component and try to connect to a closed TCP port it fails and sends a message out of the signal box, that's okay.
0
1366
by: sternr | last post by:
Hey, I'm using a TcpClient to create HTTP requests to my web-server (I know of HttpWebRequest, it is mandatory for me to use TcpClient.). Here's my code: TcpClient tcp = new TcpClient(SERVER_IP, SERVER_PORT); tcp.NoDelay = true; string data = "GET http://" + SERVER_IP + SERVER_PORT + "/getData?id=1
0
8680
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
8609
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9169
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...
0
9030
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8899
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
7738
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
4371
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
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2335
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.