Re: Problem using sockets



Rainer Temme wrote:
sam.barker0@xxxxxxxxx wrote:

In some cases I can bind the port ,but I cannot connect.And the
program hangs there till it times out.How can can I avoid this?

The connect call blocks until the connection is extablished or until
its clear that it has failed to connect. The only way around this
behaviour is to use the socket in nonblocking mode. In this case
connect() will return immediately with returncode -1 and errno set to
EINPROGRESS.

But you're still going to need a timeout. You send a packet to the
remote side, and it will reply back with a response eventually.
But how quickly? It depends on network latency, network congestion
(and dropout rates), and the load on the remote host. The only
thing a non-blocking connect() is going to get you is more control
over the timeout. Well, I guess it also gives you the ability
to try both connections simultaneously by doing two non-blocking
connect()s and then sharing one timeout for both of them.

- Logan
.



Relevant Pages

  • Re: Timeout strategy: terminal vs Telnet drivers
    ... Isn't this why you have the choice of blocking and non-blocking? ... you're sensible enough to use the $QIO interface then you have the benefit ... > goto loop if not timeout. ... > "sleep" when data stops coming. ...
    (comp.os.vms)
  • Re: Thread with timeout, pls help
    ... or a constructor overload where you can set the timeout. ... > after 2 seconds if I don't get any answer from the remote host. ... > private string mib_read ... > ManagerSession sess = new ManagerSession; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: System Calls Hang in Multi-Threaded Webcrawler
    ... You don't know for sure that it is non-blocking here, ... inline bool set_non_blocking ... Maybe something is wrong with my select routine. ... bool Select(int m_sock, int timeout) ...
    (comp.programming.threads)
  • Re: socket read behavior
    ... > implemented with non-blocking calls, ... either received the entire transaction or a timeout occurs. ... }// loop end ... receiving of the data. ...
    (comp.unix.programmer)
  • Re: Bug/Weak Implementation? popen* routines cant handle simultaneous read/write?
    ... You need pseduo-ttys and non-blocking IO. ... I use for UNIX systems then it would be easy. ... includes a timeout. ... and only one character ...
    (comp.lang.python)