Click here to Skip to main content
16,016,076 members
Home / Discussions / C#
   

C#

 
GeneralRe: Dynamic Value from an Object Pin
J4amieC19-Apr-06 0:36
J4amieC19-Apr-06 0:36 
GeneralRe: Dynamic Value from an Object Pin
723719-Apr-06 16:03
723719-Apr-06 16:03 
Question[Message Deleted] Pin
HariKreddy18-Apr-06 23:33
HariKreddy18-Apr-06 23:33 
AnswerRe: browser compatibility Pin
alexey N19-Apr-06 0:00
alexey N19-Apr-06 0:00 
AnswerRe: browser compatibility Pin
CWIZO19-Apr-06 1:54
CWIZO19-Apr-06 1:54 
QuestionNUnit with VSTS Pin
deeps2618-Apr-06 22:48
deeps2618-Apr-06 22:48 
Questionsimple client/server Pin
Bekham18-Apr-06 22:17
Bekham18-Apr-06 22:17 
AnswerRe: simple client/server Pin
Mike Dimmick19-Apr-06 1:12
Mike Dimmick19-Apr-06 1:12 
You need to use some other protocol - it can, if you insist, be one you design yourself - on top of TCP because TCP does not preserve message boundaries, so you need to tell the receiver how much data to expect, or look for some terminator.

For example, HTTP terminates the headers with a blank line (the sequence CR-LF-CR-LF) and either uses the Content-Length header to indicate how much data is present, or closes the connection once all data has been transmitted (IIRC). FTP uses a separate connection for data transfer, the end of the data being signalled by closing the connection.

UDP preserves message boundaries but is not reliable - you have no way to know whether a particular packet has arrived unless you code the receiver to send acknowledgements. You often find that you end up reinventing about 90% of TCP if you try to come up with a multi-block data-transfer scheme. You should not send more data in one message than the network can actually fit into an IP packet (the Maximum Transmission Unit), because otherwise the datagram will be fragmented, which has a massively detrimental effect on datagram loss. Say that packet loss in the route to the receiver is 5%. The chances of a datagram that fits into a single packet arriving is 95%. The chances of a datagram that must be split into two packets (fragments) arriving successfully is 95% x 95% = 90.25%, so you now get nearly 10% packet loss. The problem gets worse the more fragments you have.

Unfortunately different networks have different MTU sizes. TCP has a feature called Path MTU Discovery which allows it to work out how much data it can send in one packet without causing fragmentation. This feature relies on Internet Control Message Protocol (ICMP) responses from routers when asked to process a packet too big for the network it would be sent on. These messages will not be passed on to your application by the TCP/IP stack, so you cannot reimplement this feature in your own UDP-based protocol.

Stick to using UDP for single request/response pairs that will fit in a single packet, and use TCP for everything else. For file transfers I'd definitely use TCP.

For more information on the protocols, see the Winsock Programmer's FAQ[^]. This is oriented more towards native, rather than managed, programming, but should still be useful.

The .NET Framework contains a canned implementation of the HTTP protocol - see the HttpWebRequest class. .NET 2.0 has an implementation of FTP: FtpWebRequest. If you want to implement your own TCP-based protocol, see TcpListener for the server end and TcpClient for the client end. For UDP, see UdpClient. If you want to program the sockets directly, there's also the Socket class.

Stability. What an interesting concept. -- Chris Maunder
QuestionCreate updates of my Setup project… Pin
anderslundsgard18-Apr-06 22:09
anderslundsgard18-Apr-06 22:09 
AnswerRe: Create updates of my Setup project… Pin
Aaron Dilliard19-Apr-06 3:57
Aaron Dilliard19-Apr-06 3:57 
GeneralRe: Create updates of my Setup project… Pin
anderslundsgard19-Apr-06 21:42
anderslundsgard19-Apr-06 21:42 
Questioncan't Connect to Mysql 10048 Pin
abhinish18-Apr-06 21:52
abhinish18-Apr-06 21:52 
AnswerRe: can't Connect to Mysql 10048 Pin
HimaBindu Vejella18-Apr-06 22:54
HimaBindu Vejella18-Apr-06 22:54 
AnswerRe: can't Connect to Mysql 10048 Pin
Mike Dimmick19-Apr-06 2:04
Mike Dimmick19-Apr-06 2:04 
Questioncrystall report viewer [modified] Pin
iman_kh18-Apr-06 21:27
iman_kh18-Apr-06 21:27 
AnswerRe: crystall report viewer Pin
crazymubashir19-Apr-06 20:13
crazymubashir19-Apr-06 20:13 
QuestionPlug-in based development… Pin
anderslundsgard18-Apr-06 21:16
anderslundsgard18-Apr-06 21:16 
AnswerRe: Plug-in based development… Pin
Jon Hulatt19-Apr-06 0:39
Jon Hulatt19-Apr-06 0:39 
GeneralRe: Plug-in based development… Pin
anderslundsgard19-Apr-06 3:21
anderslundsgard19-Apr-06 3:21 
QuestionUse dll file written by C++ MFC in C# Pin
cuongcntt200218-Apr-06 21:08
cuongcntt200218-Apr-06 21:08 
AnswerRe: Use dll file written by C++ MFC in C# Pin
Aaron Dilliard19-Apr-06 4:01
Aaron Dilliard19-Apr-06 4:01 
QuestionException: Array index out of bounds Pin
Kranti125198418-Apr-06 21:03
Kranti125198418-Apr-06 21:03 
AnswerRe: Exception: Array index out of bounds Pin
Tehnoon18-Apr-06 22:09
Tehnoon18-Apr-06 22:09 
GeneralRe: Exception: Array index out of bounds Pin
J4amieC18-Apr-06 22:11
J4amieC18-Apr-06 22:11 
AnswerRe: Exception: Array index out of bounds Pin
Guffa18-Apr-06 22:09
Guffa18-Apr-06 22:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.