public abstract class AbstractSocketServerXSocket extends AbstractSocketServer implements org.xsocket.connection.IConnectHandler, org.xsocket.connection.IDisconnectHandler, org.xsocket.connection.IDataHandler, org.xsocket.connection.IIdleTimeoutHandler, org.xsocket.connection.IConnectionTimeoutHandler, ISocketServerConnectionListener
Modifier and Type | Field and Description |
---|---|
protected static boolean |
activateConnectionLogging
True to allow xSocket connection to log.
|
protected org.xsocket.connection.IServer |
srv
xSocket server.
|
protected TransferRateCalculator |
transferRate
Calculates transfer rates.
|
DEFAULT_TCP_BUFFERS_SIZE, listenPort, nWorkersCPUmultiplier, nWorkersIO, protocolDecoderFactory, tcpBufferSizeIn, tcpBufferSizeOut, workerPool
Constructor and Description |
---|
AbstractSocketServerXSocket(ISocketServerProtocolDecoderFactory protocolFactory,
int listenPort)
Constructor.
|
AbstractSocketServerXSocket(ISocketServerProtocolDecoderFactory protocolFactory,
int listenPort,
SSLContext sslContext,
int idleTimeout,
int connectionTimeout)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the server.
|
org.xsocket.connection.IServer |
getServerXSocket()
Returns the xSocket server class.
|
long |
getTotalReadBytes()
Returns the total number of bytes read.
|
long |
getTotalSentBytes()
Retuns the total number of bytes sent.
|
float |
getTransferRateIn()
Incoming data transfer rate in bytes/second.
|
float |
getTransferRateOut()
Outgoing data transfer rate in bytes/second.
|
boolean |
onConnect(org.xsocket.connection.INonBlockingConnection connection)
Socket connected.
|
boolean |
onConnectionTimeout(org.xsocket.connection.INonBlockingConnection connection)
Method called when a connection timeout is reached.
|
boolean |
onData(org.xsocket.connection.INonBlockingConnection connection)
New data available on xSocket connection.
|
boolean |
onDisconnect(org.xsocket.connection.INonBlockingConnection connection)
Disconnect event.
|
boolean |
onIdleTimeout(org.xsocket.connection.INonBlockingConnection connection)
Idle time out event.
|
void |
packetSent(ISocketServerConnection connection,
int size)
Data sent notification.
|
void |
run()
Stars the server in the current thread.
|
static void |
setActivateConnectionLogging(boolean activateConnectionLogging)
Sets the xSocket connection log.
|
void |
setIP(String ip)
Sets the IP to bind the port.
|
void |
start()
Starts the server in a different thread.
|
setPort
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
packetArrived, socketConnected, socketDisconnected, socketException
protected TransferRateCalculator transferRate
protected static boolean activateConnectionLogging
protected org.xsocket.connection.IServer srv
public AbstractSocketServerXSocket(ISocketServerProtocolDecoderFactory protocolFactory, int listenPort)
protocolFactory
- protocol decoder factory to be used by the serverlistenPort
- port to be used by the server to accept incoming connectionspublic AbstractSocketServerXSocket(ISocketServerProtocolDecoderFactory protocolFactory, int listenPort, SSLContext sslContext, int idleTimeout, int connectionTimeout)
protocolFactory
- protocol decoder factory to be used by the server.listenPort
- port to be used by the server to accept incoming connections.sslContext
- SSLContext.idleTimeout
- milliseconds to receive some data, connection will be closed
if no data is received. 0 to disable timeout.connectionTimeout
- milliseconds to close the connection after being established.
0 to disable timeout.public static void setActivateConnectionLogging(boolean activateConnectionLogging)
activateConnectionLogging
- true to allow xSocket connection to logpublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in interface ISocketServer
IOException
- error closing the socket server.public org.xsocket.connection.IServer getServerXSocket()
public long getTotalReadBytes()
getTotalReadBytes
in interface ISocketServer
public long getTotalSentBytes()
getTotalSentBytes
in interface ISocketServer
public float getTransferRateIn()
getTransferRateIn
in interface ISocketServer
public float getTransferRateOut()
getTransferRateOut
in interface ISocketServer
public boolean onConnect(org.xsocket.connection.INonBlockingConnection connection) throws IOException
onConnect
in interface org.xsocket.connection.IConnectHandler
connection
- new xSocket connection openedIOException
- error handling new connectionpublic boolean onConnectionTimeout(org.xsocket.connection.INonBlockingConnection connection) throws IOException
onConnectionTimeout
in interface org.xsocket.connection.IConnectionTimeoutHandler
connection
- the connectionIOException
- error handling connection timeoutpublic boolean onData(org.xsocket.connection.INonBlockingConnection connection) throws IOException
onData
in interface org.xsocket.connection.IDataHandler
connection
- the connectionIOException
- error while processing incoming data.public boolean onDisconnect(org.xsocket.connection.INonBlockingConnection connection) throws IOException
onDisconnect
in interface org.xsocket.connection.IDisconnectHandler
connection
- the disconnected connectionIOException
- error handling disconnect eventpublic boolean onIdleTimeout(org.xsocket.connection.INonBlockingConnection connection) throws IOException
onIdleTimeout
in interface org.xsocket.connection.IIdleTimeoutHandler
connection
- the idle connectionIOException
- error handling idle timeoutpublic void packetSent(ISocketServerConnection connection, int size)
packetSent
in interface ISocketServerConnectionListener
connection
- connectionsize
- the size of the data sentpublic void run() throws IOException
run
in interface ISocketServer
IOException
- error starting the serveres.tsbsoluciones.socketServer.ISocketServer#run()
public void setIP(String ip)
setIP
in interface ISocketServer
ip
- the IP to be used to bind the portpublic void start() throws IOException
start
in interface ISocketServer
IOException
- error starting the serverCopyright © 2018 universAAL Consortium. All rights reserved.