Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting the socket timeout?  RSS feed

 
Mike London
Ranch Hand
Posts: 1337
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to be able to set the timeout for how long the socket code below waits (tries) to connect to the remote SMTP server.

If I turn the modem off so there's no way to connect to the remote SMTP sever, this code still takes about 10 seconds to return an IOException.

I've tried it with and without the setTcpNoDelay(true) and the setSoTimeout(1).

Is it possible to set the timeout so the code returns more quickly or is this a blocking issue of some kind?

Thanks in advance.

-- Mike


Socket s = new Socket();
s.setTcpNoDelay(true);
s.setSoTimeout(1); // ms

s = new Socket("mail.somedomain.com", 25);

.
.
.
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are creating two different Socket instances. You creat an unconnected socket instance, set the timeout and delay, then replace it with a connected socket instance with the default timeout and delay. You want to invoke connect() on your first socket instance to connect using the timeout and delay values you've specified.
 
Henry Wong
author
Sheriff
Posts: 22846
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this topic to the "sockets and protocols" forum...
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!