Hi Paresh,
Thanks for the reply. My server starts and do not throw any exception, so I
assume they are running. You can check the following code (same as that
provided in the Mina documentation on the site). If you run this on two
windows, they both will be running, though only one receives the commands.
public class MinaTimeServer {
private static final int PORT = 9123;
public static void main(String[] args) throws IOException {
ByteBuffer.setUseDirectBuffers(false);
ByteBuffer.setAllocator(new SimpleByteBufferAllocator());
// IoAcceptor acceptor = new SocketAcceptor();
IoAcceptor acceptor = new DatagramAcceptor();
SocketAcceptorConfig cfg = new SocketAcceptorConfig();
cfg.getFilterChain().addLast( "logger", new LoggingFilter() );
cfg.getFilterChain().addLast( "codec", new ProtocolCodecFilter( new
TextLineCodecFactory( Charset.forName( "UTF-8" ))));
acceptor.bind( new InetSocketAddress(PORT), new TimeServerHandler(),
cfg);
System.out.println("MINA Time server started.");
}
}
--------------
public class TimeServerHandler extends IoHandlerAdapter {
public void exceptionCaught(IoSession session, Throwable t) throws
Exception {
t.printStackTrace();
session.close();
}
public void messageReceived(IoSession session, Object msg) throws
Exception {
String str = msg.toString();
if( str.trim().equalsIgnoreCase("quit") ) {
session.close();
return;
}
Date date = new Date();
session.write( date.toString() );
System.out.println("Message written...");
}
public void sessionCreated(IoSession session) throws Exception {
System.out.println("Session created...");
if( session.getTransportType() == TransportType.SOCKET )
((SocketSessionConfig) session.getConfig()
).setReceiveBufferSize( 2048 );
session.setIdleTime( IdleStatus.BOTH_IDLE, 10 );
}
}
Am i missing something here?
Regards,
Hari
--- On Wed, 4/8/09, PARESH BHAVSAR <[email protected]> wrote:
> From: PARESH BHAVSAR <[email protected]>
> Subject: Re: Datagram Socket Binding Problem
> To: [email protected]
> Date: Wednesday, April 8, 2009, 9:27 PM
> Hi Hari,
> I have used MINA too for the UDP. It should not bind to the
> same port please
> check whether your application is running.
>
> Give me your personal id so that we can talk offline as i
> am also in the
> same type of programming.
>
> bye
> paersh
>
> On Wed, Apr 8, 2009 at 11:30 AM, Ponnapalli Hari Gopal
> <
> [email protected]>
> wrote:
>
> >
> > Hi,
> > I am bit new to the network programming. I am
> developing a server based on
> > Mina using datagram sockets. I am bit confused with
> the datagram sockets
> > here. When I start an instance of the server on a port
> (say 1812) it starts.
> > However, when I run a second instance of the
> server on same port, it also
> > binds to that port successfully. I am expecting that
> the bind should fail
> > here as the port is already in use, the TCP/IP
> way. Is it an expected
> > behavior of UDP datagrams?
> >
> > If this is the expected behavior, how do I know which
> instance of the
> > server receives the packets?
> >
> > Basically, I am trying to develop a RADIUS server on
> top of Mina. The
> > server is up and running. However, if there are
> multiple instances of the
> > server running, sometimes I am facing strange behavior
> in terms of none of
> > the servers are receiving the packets.
> >
> > Can someone provide any pointers on how to developa
> datagram server
> > reliably. I also want to provide some start, shutdown
> scripts that allows
> > the users to start, stop the server. For this,
> any guidance on what is the
> > approach to be followed. If I start the server in a
> new thread, and close
> > the main program, the server thread also (being child)
> is getting closed.
> > So, do I need to start a separate port on which server
> listens for
> > administrative commands like start, shutdown? In such
> case how to provide
> > authentication of it? Or shall I need to use some
> shared memory (flag) that
> > will be used by both server and startup/shutdown
> scripts. In such case the
> > server requires constant polling of the shared
> variable to start/stop the
> > server.
> >
> > Also does the RADIUS need to be mandatarily supported
> only on UDP?
> >
> > Sorry for my stupid questions, but, any ideas/guidance
> on same is highly
> > appreciated.
> >
> > Regards,
> > Hari
> >
> >
> >
> >
>