Skip to main content
GameDev.net gamedev.net
🔒 Locked

Java SocketChannel Read Problem

Started by fathom88 Dec 10, 2008 at 1:40 PM 0 replies 1.9k views
Original Post
fathom88
fathom88
Is there a max rate Java's SocketChannel can read data at? I always assumed the max rate would be whatever your hardware connection is. In my case, it's two PC's next to each other connected by an ethernet cable. I must conclude there is a problem with my read code. My server sends 2.5 MB of data to my client every 1 sec. My client seems to take 3 or 4 sec to read the 2.5 MB of data. I'm new to using the SocketChannel and assume I'm doing something wrong. Here is my read code which gets called inside my void run() with a "Thread.sleep(1)" ByteBuffer buf = ByteBuffer.allocateDirect(1024); try { // Clear the buffer and read bytes from socket buf.clear(); int numBytesRead = socketChannel.read(buf); if (numBytesRead == -1) { // No more bytes can be read from the channel socketChannel.close(); } else { //Read bytes; currently commented out to do nothing to prevent //any slow down from processing the data } } catch (IOException e) { // Connection may have been closed } I tried to increase the read buffer. I've to set my sleep to zero. Both attempts didn't speed up the read.
ractoc
ractoc
Please don't double post.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.