Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-13-2009, 02:24 PM
Member
 
Join Date: Nov 2008
Posts: 4
Rep Power: 0
aamp is on a distinguished road
Question Sockets NIO
So after reading some material regarding nonblocking IO I've decided to write a server with NIO. In traditional, blocking IO, I was having a seperate thread for each of my clients, so I always knew what client sent me what data. But now, I just select a readable key and read it's data. How do I know which client sent what data? Is it efficient to make a HashMap where keys are SocketChannels and values are references to my Client objects? Or is it secure to give each client an unique ID and require them to communicate by always sending it?

Looking forward for your comments.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 01-14-2009, 06:38 AM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 1,018
Rep Power: 3
Nicholas Jordan is on a distinguished road
Post require key
I dug into this a few months ago, what the servers I found were using as an idea of a Session,.....uh, it needs work.

NIO is popular, and has some good work. I expect it will rely on existing pardigm of what a session is, thus multiple connects from one machine would appear as one session, not exactly what I thought of as a sesssion.

I suggest a synchronized block on entry, writing a session key at random if none ... then do something along the lines of what you are thinking but be sure to do the lookup on the key in that block - doing so on the session key that reads on the SocketChannel. Dicey I would think, not for scaling and commercial app.

Use SecureRandom, generate a Key. Pass that key to a HTTP 1.0 GET ... just come up with another one and look for it to come in as POST - doing so by writing the key to <form> ('s) keeping in mind that a web is the work of spiders .... don't expose yourself to spider bites.....

This design challenge has a issues in scaling and server load. If requests come in as much as a hundred a second at some point, some designs will bog ( or lose keys ) so it matters much if this is a student project or a deployable commercial app. Several things have been fixed in 5.0 6.0 and 7.0 - that does not matter much to me, I still plan on calling into a dll through jni when I can get the skills to do it, too many times something that is simple and obvious only gets surface treatment: Try hardcoding a line ending as \u000a or whatever it is, watch and moan.....
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-14-2009, 07:32 AM
Senior Member
 
Join Date: Nov 2008
Posts: 265
Rep Power: 1
neilcoffey is on a distinguished road
Default
See the SelectionKey.attach() method. You can use this to attach some "state object" to the SelectionKey representing the "conversation" with the client in question (and the attachment() method retrieves the state previously attached).
__________________
Neil Coffey

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-15-2009, 10:56 AM
Member
 
Join Date: Nov 2008
Posts: 4
Rep Power: 0
aamp is on a distinguished road
Default
Thanks for your posts. Helps a lot
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Threads + Sockets Tomdarkness New To Java 1 12-24-2008 12:06 AM
Java application using sockets! rameshraj Threads and Synchronization 1 06-11-2008 06:13 PM
Sending files over sockets! rameshraj Networking 2 05-30-2008 10:18 PM
Sockets Zosden Networking 16 05-27-2008 04:55 PM
Help with Sockets Eric Networking 3 12-01-2007 08:09 PM


All times are GMT +2. The time now is 08:21 AM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org