Skip to content

Vortex IO is an easy-to-use high performance non-blocking zero dependency socket server API for Java.

License

Notifications You must be signed in to change notification settings

Konloch/Vortex-IO

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

81 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vortex IO

Vortex IO is a high preformant low-level non-blocking tcp socket server API. Click here for the core library source code.

💡 Requirements

  • Java Runtime 1.8 or higher

⚙️ How To Add As Library

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>

📚 Links

💻 How To Use

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();