Yes, UDP is "connectionless" but what he is looking to do can be done fairly easily with Mina.
Create a hashmap. As the key of the hashmap use the remote ip address of the client which you can obtain from the iosession. If you could have multiple clients from the same IP on different ports then store a combination of the remote client's ip and port as the key of the hashmap. The value of the hashmap should be the iosession. When you get a message from a client you should check if that clients IP is in the hashmap. If not, add it and the iosession. Later when you want to send a message to the clients you can get them from the hashmap. You should also probably implement a protocol specific message that allows the client to tell the server "disconnect". I.E. I don't want any more messages. I would also recommend implementing a timeout or something that if you don't interact with a client after XX minutes or seconds there iosession is automatically removed from the hashmap. This will help to alleviate problems of a client going off-line without telling you they want to "disconnect" first. Of course if you implement that and your client isn't very chatty they may get removed from the hashmap accidentally. So you would need to implement a protocol specific keep alive message as well. None of this is particularly hard, but it will take a good bit of time to build it, debug it and get it all correct. I would seriously consider using TCP instead because it helps to simplify everything. But if you need UDP it can be done. Another thing to consider before implementing this all with UDP is the popularity of Network Address Translation (NAT) routers and firewalls deployed in people's homes. If your client makes a connection outbound by UDP your server _should_ be able to reply to that client by UDP, but only for a limited time. Every NAT router and firewall is different, so some might have shorter or longer time periods that they keep a port open as the result of an outgoing message. So just be careful because you might run into a situation where everything was working fine on your development network or a corporate network but then when deployed live on the internet people are having all sorts of odd problems. Using keep alive message with a short enough timeout (60 seconds?) would help this issue some, but you'll still run into it on occassion. TCP would again help to alleviate much of this potential problem, and TCP with keep alive messages would be much easier to implement and probably all but eliminate this potential problem. Hope this helps. Rob --- Julien Vermillard <[EMAIL PROTECTED]> wrote: > Le mercredi 19 juillet 2006 à 13:20 -0400, Joao a > écrit : > > I have a datagram server which receives > information from many > > sources. > > I want to keep a session open for every end > point the server > > receive a message from. > > > > How can I keep a session for every new > connector point I receive > > a message from? > > > > > > > > Thanks, > > > > Joao, > > UDP is a connection less protocol, I'll probably > sound annoying but > perhaps you should use TCP ? > > Julien > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
