Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
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  
  SocketChannel doesn't wait  (Read 2108 times)
0 Members and 1 Guest are viewing this topic.
Offline Raven

Senior Newbie




Java games rock!


« Posted 2003-12-08 08:11:09 »

Hi there,

the Socket Channel doesn't wait for incoming messages. The select() Method always return.

--> I got 100% CPU utilization because the while is always running.

Any suggestions ?

Here is the code snippet:

InetSocketAddress socket = new InetSocketAddress("C9769CE0",8100);
           socketChannel = SocketChannel.open();
           socketChannel.configureBlocking(false);
           socketChannel.connect(socket);      
           socketChannel.finishConnect();      
           
           Selector selector = SelectorProvider.provider().openSelector();            
           SelectionKey key = socketChannel.register(selector,SelectionKey.OP_READ);
           CharBuffer charBuffer = CharBuffer.allocate(1024);
           b.clear();      
           int keysAdded;
           while (true)
           {
             key.selector().select();
                                 ................


--> the select method dont wait here for incoming messages ?
Offline elias

Senior Duke





« Reply #1 - Posted 2003-12-08 09:04:16 »

You might have an error condition waiting on the socket (like "Could not connect"). Have you checked that?

- elias

Offline kaffiene
« Reply #2 - Posted 2003-12-09 01:00:32 »

socketChannel.configureBlocking(false);

That would be the problem, wouldn't it?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #3 - Posted 2003-12-09 06:33:59 »

Quote
socketChannel.configureBlocking(false);

That would be the problem, wouldn't it?


I would be surprised...

Selector.select() *does* block, indefinitely, according to the NIO specification.

From the API docs, a READ selector ought to block until one of it's channels has received incoming data which your code has not yet read out, OR until any of its channels has been disconnected (not in the docs Sad).

There are other alternatives, but these are all official bugs with e.g. 1.4.0 and 1.4.1 on specific platforms, and have IIRC all been fixed.

malloc will be first against the wall when the revolution comes...
Offline Raven

Senior Newbie




Java games rock!


« Reply #4 - Posted 2003-12-09 08:58:59 »

Hi,

there is a bug in the bug database from sun. It seems that I have this problem:

http://developer.java.sun.com/developer/bugParade/bugs/4850373.html

Raven
Offline elias

Senior Duke





« Reply #5 - Posted 2004-02-29 14:02:49 »

Update: It seem to be fixed in jdk1.5.0 beta2, according to the bug status.

- elias

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.

Longarmx (38 views)
2014-10-17 03:59:02

Norakomi (28 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (28 views)
2014-10-15 16:18:58

TehJavaDev (53 views)
2014-10-14 00:39:48

TehJavaDev (54 views)
2014-10-14 00:35:47

TehJavaDev (43 views)
2014-10-14 00:32:37

BurntPizza (64 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (78 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!