You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Julien Vermillard <jv...@archean.fr> on 2006/07/20 11:42:14 UTC

Re: Datagram Sessions

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

Re: Datagram Sessions

Posted by peter royal <pr...@apache.org>.
On Jul 20, 2006, at 8:16 AM, Joao wrote:
>   I know what you mean. Unfortunately, I have already 3.000 clients  
> from different vendors
>   communicating with a C version of the program. All of them using  
> UDP. I know it is hard,
>   but I need to have a kinda session  per terminal. Actually, I  
> already have a kludge that works.
>      I was just wandering if I could use the Acceptor newSession  
> method for this.

not cleanly.. since you presumably have some custom logic that lets  
you determine which packets are part of a "session" ?

>    I quickly read the code, unfortunately I could not figure out  
> how to use it, once I will create
>    the session later after receiving the first message from that  
> terminal. Just at that time I will have enough information     to  
> create it(for example the remote address).
>
>    In case anyone has a clue on how to use it, I will appreciate.

one thing you can do it put your session-determination code into an  
IoFilter, and then wrap the message in your own object when passing  
down to the next filter / your handler that adds session information.

-pete


-- 
proyal@apache.org - http://fotap.org/~osi




Re: Datagram Sessions

Posted by Joao <jo...@wireless-networks.com>.
Julien Vermillard 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 ?
>   
   I know what you mean. Unfortunately, I have already 3.000 clients 
from different vendors
   communicating with a C version of the program. All of them using UDP. 
I know it is hard,
   but I need to have a kinda session  per terminal. Actually, I already 
have a kludge that works.
   
    I was just wandering if I could use the Acceptor newSession method 
for this.
    I quickly read the code, unfortunately I could not figure out how to 
use it, once I will create
    the session later after receiving the first message from that 
terminal. Just at that time I will have enough information  
    to create it(for example the remote address).

    In case anyone has a clue on how to use it, I will appreciate.

    Thanks anyway,

Joao,
> Julien
>   


Re: Datagram Sessions

Posted by Rob Butler <cr...@yahoo.com>.
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 <jv...@archean.fr> 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