public class TcpServer extends IoHandlerAdapter
限定符和类型 | 字段和说明 |
---|---|
static int |
MAX_RECEIVED
The number of message to receive
|
static int |
PORT
The listening port (check that it's not already in use)
|
构造器和说明 |
---|
TcpServer()
Create the TCP server
|
限定符和类型 | 方法和说明 |
---|---|
void |
exceptionCaught(IoSession session,
java.lang.Throwable cause)
Invoked when any exception is thrown by user
IoHandler
implementation or by MINA. |
static void |
main(java.lang.String[] args)
The entry point.
|
void |
messageReceived(IoSession session,
java.lang.Object message)
Invoked when a message is received.
|
void |
sessionClosed(IoSession session)
Invoked when a connection is closed.
|
void |
sessionCreated(IoSession session)
Invoked from an I/O processor thread when a new connection has been created.
|
void |
sessionIdle(IoSession session,
IdleStatus status)
Invoked with the related
IdleStatus when a connection becomes idle. |
void |
sessionOpened(IoSession session)
Invoked when a connection has been opened.
|
inputClosed, messageSent
public static final int PORT
public static final int MAX_RECEIVED
public TcpServer() throws java.io.IOException
java.io.IOException
- If something went wrongpublic void exceptionCaught(IoSession session, java.lang.Throwable cause) throws java.lang.Exception
IoHandler
implementation or by MINA. If cause
is an instance of
IOException
, MINA will close the connection automatically.exceptionCaught
在接口中 IoHandler
exceptionCaught
在类中 IoHandlerAdapter
session
- The session for which we have got an exceptioncause
- The exception that has been caughtjava.lang.Exception
- If we get an exception while processing the caught exceptionpublic void messageReceived(IoSession session, java.lang.Object message) throws java.lang.Exception
messageReceived
在接口中 IoHandler
messageReceived
在类中 IoHandlerAdapter
session
- The session that is receiving a messagemessage
- The received messagejava.lang.Exception
- If we get an exception while processing the received messagepublic void sessionClosed(IoSession session) throws java.lang.Exception
sessionClosed
在接口中 IoHandler
sessionClosed
在类中 IoHandlerAdapter
session
- The session being closedjava.lang.Exception
- If we get an exception while processing the close eventpublic void sessionCreated(IoSession session) throws java.lang.Exception
sessionCreated
在接口中 IoHandler
sessionCreated
在类中 IoHandlerAdapter
session
- The session being createdjava.lang.Exception
- If we get an exception while processing the create eventpublic void sessionIdle(IoSession session, IdleStatus status) throws java.lang.Exception
IdleStatus
when a connection becomes idle.
This method is not invoked if the transport type is UDP; it's a known bug,
and will be fixed in 2.0.sessionIdle
在接口中 IoHandler
sessionIdle
在类中 IoHandlerAdapter
session
- The idling sessionstatus
- The session's statusjava.lang.Exception
- If we get an exception while processing the idle eventpublic void sessionOpened(IoSession session) throws java.lang.Exception
IoHandler.sessionCreated(IoSession)
. The biggest difference from
IoHandler.sessionCreated(IoSession)
is that it's invoked from other thread
than an I/O processor thread once thread model is configured properly.sessionOpened
在接口中 IoHandler
sessionOpened
在类中 IoHandlerAdapter
session
- the current seessionjava.lang.Exception
- If something went wrongpublic static void main(java.lang.String[] args) throws java.io.IOException
args
- The argumentsjava.io.IOException
- If something went wrong