I'm trying to make a basic server application (which I will eventually mold into something for a game I am working on), but I am having a lot of trouble understanding exactly what's going on. I included my Server class below.

Server started on port 4123
To test, I just run telnet -> open localhost 4123 -> type stuff
When I open the connection, the server prints this (as it should):Accepted: /0:0:0:0:0:0:0:1:50543
Then, every time I type a single character it prints:In From: /0:0:0:0:0:0:0:1:50540
Read: 0000000000000000
The data is always all zeros.
Then, when I disconnect by closing the cmd prompt (telnet), it just constantly prints the read message again forever.In From: /0:0:0:0:0:0:0:1:50540
Read: 0000000000000000
In From: /0:0:0:0:0:0:0:1:50540
Read: 0000000000000000
In From: /0:0:0:0:0:0:0:1:50540
Read: 0000000000000000
In From: /0:0:0:0:0:0:0:1:50540
Read: 0000000000000000
...

I haven't worked with the nio packages yet. Did you put this program together yourself or did you copy if from the tutorials or somewhere else?

08-24-2012, 12:20 AM

AndrewM16921

Re: Help with NIO Server

Little bit of both. I based it off a few tutorials I was reading.

08-24-2012, 02:01 AM

Norm

Re: Help with NIO Server

Have you tried doing some debugging by printing out some values For example how many bytes are read by the read() method? What are the values for all the states of the ByteBuffer object? It has lots of methods to call for status.