Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2008

Tip: Looking for answers? Try searching our database.

Java networking problem

Thread view: 
nooneinparticular314159@yahoo.com - 18 Mar 2008 16:56 GMT
Greetings.  I'm having a major problem with Java NIO networking.  I'm
trying to get two clients to talk to each other over a network
connection.  I'm able to get the clients to write to the network, and
the data clearly gets to the machine on the other side of the
network.  But for some reason, the other client never gets its channel
marked as readable, and therefore the other client never reads in the
data.  Eventually, the input buffer on the receiving client fills, and
the sending client stops writing.  I've shown what I'm doing below.
Does anybody know what I'm doing wrong, and how I can fix it?

Thanks!

I'm initially registering the channel as:
AcceptedChannel.register(ChannelSelector, SelectionKey.OP_READ |
SelectionKey.OP_WRITE);
(I've also tried setting it up intially as:
AcceptedChannel.register(ChannelSelector, SelectionKey.OP_READ);
but that doesn't seem to work (as it shouldn't, since I need to be
able to both read and write.)

The next thing it hits (assuming that there is a key) is usually if
(NextKey.isWritable())
(It hits the test for readability first, but I never get a readable
channel)

It gets the appropriate channel based on that key:
NetworkDataHandler Handler = DataHandlerContainer.Get((SocketChannel)
NextKey.channel());

and then the object associated with that specific channel tries to set
up a message and write to it:
MessageHandlerForThisChannel.SendTestMessage();

That creates a test message (currently a string about wishing that my
program would work!), encodes it in a byte array, and adds it to my
outgoing message queue.

A message sending method is then called, which checks for messages on
the queue.  If any exist, it gets the next one and places it in the
SendBuffer.  It then does a

Channel.write(SendBuffer);

to write out the data.  I've tried various combinations of registering
teh channel for OP_READ, OP_READ | OP_WRITE, or OP_WRITE after this,
and none of them worked (although registering for read only certainly
prevented more data from being written.  :-)  )

After the data is written out to the channel, it definitely appears on
the remote host.  Using Ethereal, I've been able to confirm that both
clients send the test message to each other.  Using Telnet, I've also
been able to confirm that the message is sent to remote clients.
Ethereal also confirmed that both clients are writing to and from the
same ports on each machine, so they are clearly using the same channel
in each direction.  However, despite the data making it at least as
far as the remote host, the OP_READ is never triggered, and therefore
the data is never read.  Unless, of course, I send the data through
telnet, in which case it is.  Actually, I also tried writing a non-
blocking client that does an OP_CONNECT instead of a read or write,
that one seems to be able to get data through to the client (although
it doesn't try to read any.)  That client uses the same reading and
writing methods as my regular client.  Only the setup is different.

Any ideas?  Thanks!
EJP - 19 Mar 2008 00:30 GMT
[repost]

Please don't do that. You're getting plenty of responses in your
original thread.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.