Re: socket programming
- From: "sirisha" <sirishamohan2000@xxxxxxxxx>
- Date: 8 Jun 2006 04:55:46 -0700
Thank you David, as u said it is correct, but I am not receiving any
errors while i am debugging it, so how can i find the return codes of
socket interface. so, please tell me the method how to develop the
application from scracth. i am asking this as i am a fresher.
regards,
sirisha.
David wrote:
Sirisha,
Scott already answered this, but I'd like to make sure that you
understand a bit how TCP is designed to work. As Scott mentioned,
your code exits on every error and does not attempt to recover in
any way. There are return codes from the socket interface that
are not successful and don't indicate an error. One good example
is that repeated send requests may eventually block or 'fail'
with a "please wait, send queue busy" state. This can be the
result of the receiver not keeping up or the TCP/IP pipeline
simply being full and needing some time to empty. In short,
you must check every return code when using sockets and perform
a reasonable action based on the status returned. Some status
messages tell you to wait or to start sending again. Some
are "expected temporary errors" and others truely are "fatal
errors". For instance, opening lots of sockets for communciation
may fail on systems with limited resources. Just wait and retry
the action. There are some rather good examples out there on
how to communicate with sockets. I prefer the ancient Unix
examples for clients, simple servers, multi-protocol servers,
and multi-protocol, multi-service servers. Most of these can
be found and written without too much effort (but a great deal
of care). Windows examples tend to be larger and use the Windows
event model, but it is generally the same thing.
TCP/IP and UDP/IP or even IP socket communications must be
handled much like a serial interface. That is, they have normal
open/close/transmit/receive sequences, and lots of buffer overrun/
underrun states that can also occur. There is no such thing as
a simple socket action. Even the act of sending a message must
some how be wrapped or handled in your code to insure that the
entire message is sent.
As for the memory leaks, they don't really hurt anything,
at least in terms of affecting soemthing else. However,
a nice tight loop that opens sockets and fails to send
and then never cleans up will quickly use up all sockets
in your system. Many systems clean up after the application
ends, but some don't to that for sockets. Those are rare
these days.
David
.
- Follow-Ups:
- Re: socket programming
- From: David
- Re: socket programming
- References:
- socket programming
- From: sirisha
- Re: socket programming
- From: David
- Re: socket programming
- From: sirisha
- Re: socket programming
- From: David
- socket programming
- Prev by Date: Re: Default path for application and LoadLibrary
- Next by Date: I have a question with repeat open and close table
- Previous by thread: Re: socket programming
- Next by thread: Re: socket programming
- Index(es):
Relevant Pages
|