Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (416)
games submitted by our members
Games in WIP (306)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  NIO SocketChannel connect with timeout  (Read 5199 times)
0 Members and 1 Guest are viewing this topic.
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Posted 2007-08-16 21:17:30 »

Socket got a connect(address, timeout) method a couple JRE versions ago.
We also got NIO with SocketChannel so we could use Selectors...
but SocketChannel's connect method doesn't take a timeout parameter.

Does somebody need to be shot, or is there a way to use Channels AND connect to a socket with timeout?

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 463
Projects: 4


Hand over your head.


« Reply #1 - Posted 2007-08-16 21:51:24 »

 Huh

socketChannel.socket().setSoTimeout(ms);

Or did you mean something else?

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Projects: Revenge of the Titans, Titan Attacks, Droid Assault, and Ultratron
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #2 - Posted 2007-08-16 23:23:17 »

but SocketChannel's connect method doesn't take a timeout parameter.

Completely off the top of my head ...

"you don't need a timeout, because SC's do a non-blocking Connect, and send a message to the Selector with message type CONNECTED when that becomes the case" Huh

malloc will be first against the wall when the revolution comes...
Games published by our own members! Check 'em out!
Try the Free Demo of Droid Assault
Offline Mr_Light

Senior Member




shiny.


« Reply #3 - Posted 2007-08-17 11:14:34 »

both of the above, you don't need a timeout for your program's flow sake, to avoid having something trying to connect forever it's already constraint by the setSoTimeout(value).

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline kevglass
« League of Dukes »

JGO Kernel


Medals: 54
Projects: 20


Mentally unstable, best avoided.


« Reply #4 - Posted 2007-08-17 13:21:00 »

Quote
socketChannel.socket().setSoTimeout(ms);

Or did you mean something else?

setSoTimeout() doesn't seem to effect connect() (on windows here at least). SO_TIMEOUT maps to SO_SNDTIMEO and SO_RCVTIMEO in the underlying setsockopt() which only effect receive and send.

Quote
you don't need a timeout, because SC's do a non-blocking Connect, and send a message to the Selector with message type CONNECTED when that becomes the case

Whether or not the socket is in blocking mode you do still want it to stop attempting to connect once packets are failing for a set period - 20 seconds by default. Just because you're not blocked by it doesn't mean you wouldn't like it to stop trying eventually and tell you that it failed. It'd still be nice to be able to configure this like you can directly on the socket.

Would:

1  
socketChannel.socket().connect(address, ms);


Work?

Kev


Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #5 - Posted 2007-08-17 15:13:41 »

Yeah, what Kev said...

setSoTimeout() doesn't affect connect(), and I want the selector to notify me sooner that the connection isn't happening.

channel.socket().connect(addr, timeout)  might work...

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
BrassApparatus (9 views)
2013-06-19 08:52:37

NegativeZero (14 views)
2013-06-19 03:31:52

NegativeZero (17 views)
2013-06-19 03:24:09

Jesse_Attard (20 views)
2013-06-18 22:03:02

HeroesGraveDev (62 views)
2013-06-15 23:35:23

Vermeer (61 views)
2013-06-14 20:08:06

davedes (61 views)
2013-06-14 16:03:55

alaslipknot (55 views)
2013-06-13 07:56:31

Roquen (77 views)
2013-06-12 04:12:32

alaslipknot (60 views)
2013-06-10 19:30:18
Smoothing Algorithm Question
by UprightPath
2013-05-28 02:58:26

Smoothing Algorithm Question
by UprightPath
2013-05-28 02:57:33

Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!