Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
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 7490 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: 757
Projects: 4
Exp: 16 years


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
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!
Legends of Yore - The Casual Retro Roguelike
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

JGO Kernel


Medals: 122
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« 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.

 

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

The first screenshot will be displayed as a thumbnail.

CogWheelz (18 views)
2014-07-30 21:08:39

Riven (26 views)
2014-07-29 18:09:19

Riven (15 views)
2014-07-29 18:08:52

Dwinin (13 views)
2014-07-29 10:59:34

E.R. Fleming (34 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (44 views)
2014-07-24 01:59:36

Riven (44 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!