public class MessageLikeSocketServer extends SocketServer
In TCP, you can't rely on separate "packets" being received separately. Sending 4 chunks of 10 bytes may be received as 1 chunk of 40 bytes, 2 chunks of 20 bytes, or one chunk of 39 and one chunk of 1 byte. TCP guarantees in order delivery, but not any particular 'packetization' of your data.
Our protocol is pretty simple. Each packet must have the following format:
------------------------------------------- | payload_length (4 bytes) | payload | -------------------------------------------
You can then easily decode received TCP packets and decode corresponding messages.
This server must be linked to a Router
.
Example of use: MessageLikeSocketServerExample
port, router, serverIpAddresses
Constructor and Description |
---|
MessageLikeSocketServer(int maxNbOfConnections,
int port,
Router router)
Constructor for a message-like socket server using the specified parameters.
|
MessageLikeSocketServer(Router router)
Constructor for a message-like socket server using the specified Router
and with the following parameter values:
Maximum number of connections: 5
Port number: Network.getAvailablePort()
|
Modifier and Type | Method and Description |
---|---|
protected void |
newThreadToDealWithClient(java.net.Socket client) |
protected void |
printServerLaunchedMessage() |
close, getIpAddresses, getPort, pause, start
public MessageLikeSocketServer(Router router)
router
- the Raspoid router to use with this server.NetworkUtilities.getAvailablePort()
public MessageLikeSocketServer(int maxNbOfConnections, int port, Router router)
maxNbOfConnections
- the maximum number of parallel connections allowed on this server.port
- the port to use with this server.router
- the Raspoid router to use with this server.protected void newThreadToDealWithClient(java.net.Socket client)
newThreadToDealWithClient
in class SocketServer
protected void printServerLaunchedMessage()
printServerLaunchedMessage
in class SocketServer