Class serverHandler
java.lang.Object
org.apache.mina.core.service.IoHandlerAdapter
name.moore.kevin.ze.game.states.remote.serverHandler
- All Implemented Interfaces:
org.apache.mina.core.service.IoHandler
public class serverHandler
extends org.apache.mina.core.service.IoHandlerAdapter
Use the static serverHandler.makeServer() to create a new server.
Register functions that handle required incoming datatypes.
- Author:
- Kevin Moore
<dev@kevin.moore.name>
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateserverHandler(org.apache.mina.core.service.IoAcceptor acceptor)Only called via the static makeServer. -
Method Summary
Modifier and TypeMethodDescriptionvoidSend the object to all connected sessions.voidvoidexceptionCaught(org.apache.mina.core.session.IoSession session, Throwable cause)static serverHandlermakeServer(int port)voidmessageReceived(org.apache.mina.core.session.IoSession session, Object message)voidregisterFunction(Class c, Consumer<Object> f)Server manager provides functions to handle different types of incoming objects.Methods inherited from class org.apache.mina.core.service.IoHandlerAdapter
event, inputClosed, messageSent, sessionClosed, sessionCreated, sessionIdle, sessionOpened
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
functions
Used to provide handling functions for incoming data. -
acceptor
private org.apache.mina.core.service.IoAcceptor acceptorThe server socket.
-
-
Constructor Details
-
serverHandler
private serverHandler(org.apache.mina.core.service.IoAcceptor acceptor)Only called via the static makeServer. Remember the socket for broadcasting messages.- Parameters:
acceptor-
-
-
Method Details
-
makeServer
- Parameters:
port-- Returns:
- Throws:
IOException
-
closeServer
public void closeServer() -
broadcast
Send the object to all connected sessions.- Parameters:
s-
-
registerFunction
Server manager provides functions to handle different types of incoming objects.- Parameters:
c- class of incoming objectf- function to handle it.
-
messageReceived
public void messageReceived(org.apache.mina.core.session.IoSession session, Object message) throws Exception- Specified by:
messageReceivedin interfaceorg.apache.mina.core.service.IoHandler- Overrides:
messageReceivedin classorg.apache.mina.core.service.IoHandlerAdapter- Throws:
Exception
-
exceptionCaught
public void exceptionCaught(org.apache.mina.core.session.IoSession session, Throwable cause) throws Exception- Specified by:
exceptionCaughtin interfaceorg.apache.mina.core.service.IoHandler- Overrides:
exceptionCaughtin classorg.apache.mina.core.service.IoHandlerAdapter- Throws:
Exception
-