Re: socket programming

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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



.



Relevant Pages

  • Re: Matching RAM
    ... > David C. wrote: ... The sockets are paired - each socket in one bank ... Perhaps the System Profiler will tell you. ...
    (comp.sys.mac.hardware.misc)
  • Re: How often should a repeated word be a link?
    ... a page David made. ... On the other hand, regardless, a font size for BODY of 70% is eggregious to say the least, and in any case I can imagine. ... Even if they are back in their sockets. ... And my psyche is still smarting from the whole experience of my eyeballs being anywhere else other than their sockets. ...
    (alt.html)
  • Netzwerkvebindungen
    ... unterbricht und sich dann ohne Neustart der Anwendung wieder verbinden ... möchte auf dem Server zwei Sockets hat. ... David ...
    (microsoft.public.de.german.entwickler.dotnet.vb)
  • Re: socket communication / callback
    ... > I'm wondering if it's possible to use sockets for the folloing purpose: ... > A running process acts as a kind of server, ... > The receiving should trigger some functions (some display update based on ... toolkits provide an event loop already; if not then there are systems on ...
    (comp.lang.perl.misc)
  • What to do? lock()? invoke()? begininvoke()?
    ... I have an application using sockets, and it uses the asynchronous method ... for receiving ... The question is, in "mySocketClass", what is the best way to send an ... What is the best way to send events from a worker thread to the main ...
    (microsoft.public.dotnet.languages.csharp)