Solved

Searching tcp client/socket class robust and reliable in .NET 2.0

Posted on 2009-04-02
4
699 Views
Last Modified: 2012-05-06
Hi experts,

i have my own  class of tcp and it works but sometimes, i have memory leak or a command that i have to send that is not sent ;(

that's why i'm asking if somebody have a wrapper tcp/socket client that can run 24/7 and when i send command, i have to be sure that the command is really sent.

regards
0
Comment
Question by:Dnx_7
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 15

Accepted Solution

by:
oobayly earned 500 total points
ID: 24048235
What's wrong with the System.Net.Sockets.TcpClient? The nature of TCP is that if a packet is mangled or received out of order, it'll be retransmitted. For every tcp packet sent, it requires an Acknowledgement packet to be received:
eg:

client -> server syn
server -> client syn, ack
client -> server ack
server -> client psh, ack
client -> server ack
server -> client fin, ack
client -> server fin, ack
server -> client ack

So the TcpClient will throw an exception if a send fails. If no exception is thrown you can be sure that the data has been sent successfuly
0
 
LVL 2

Author Comment

by:Dnx_7
ID: 24048312
i don't know because i'm still too new on network programmation but i use

myTCPClient.getstream.write(...)

i don't have any error but sometimes there is micro network disconnection or something else
but the order is not sent correctly :(

regards
0
 
LVL 15

Assisted Solution

by:oobayly
oobayly earned 500 total points
ID: 24049216
Hmm, that's a little strange as if there's a problem transport, the packet should be retried a bit like this:
  1. Resend after 3 seconds
  2. Resend after 6 seconds
  3. Resend after 12 seconds
  4. ...
  5. Timeout
and if it fails, an IOException should be throw by NetworkStream.Write()

Obviously this is an intermittent problem which are a pain to diagnose. The only way I ever managed to diagnose problems like this was to run Wireshark capture all the data sent by my client-server application, when ever something unexpected happened (such as the client sending data, but the server not receiving) I would have to trawl through the capture data and try to figure out what actually happened on the wire.
It's probably the second best way to fry your brain (after taking LSD), but if you get adept at it you'll feel like Neo in The Matrix :-)
0
 
LVL 2

Author Comment

by:Dnx_7
ID: 24183890
Thank you guys
0

Featured Post

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month8 days, 5 hours left to enroll

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question