Vortex IO is a high preformant low-level non-blocking tcp socket server API. Click here for the core library source code.
- Java Runtime 1.8 or higher
Add it as a maven dependency or just download the latest release.
<dependency>
<groupId>com.konloch</groupId>
<artifactId>Socket-Server</artifactId>
<version>0.9.4</version>
</dependency>
You can view an HTTP Server implementation here, or an IRC Server implementation here, or an Echo Server implementation here.
RFC-862 compliant echo server
SocketServer server = new SocketServer(7, client ->
{
switch(client.getState())
{
//signal we want to start reading into the buffer
case 0:
//signal that we want to start reading and to fill up the buffer
client.setInputRead(true);
//advance to stage 1
client.setState(1);
break;
//wait until the stream has signalled the buffer has reached the end
case 1:
//when the buffer is full advance to stage 2
if(!client.isInputRead())
client.setState(2);
break;
//announce the read
case 2:
//get the bytes written
byte[] bytes = client.getInputBuffer().toByteArray();
//reset the input buffer
client.getInputBuffer().reset();
//echo the bytes back
client.write(bytes);
//loop back to stage 0
client.setState(0);
break;
}
});
server.start();