Skip to content

Basic Server

gcflames5 edited this page Dec 5, 2014 · 2 revisions

Creating a basic, unauthenticated server is very easy with serverinterconnect. Simply create a new instance of a ServerManager and initialize it.

A ServerManager takes a Socket and will automatically handle incoming connections for you.

If you don't care about your packets being encrypted, you can simply pass in a regular java ServerSocket and start your server:

//First, select the port that you want to listen o
int port = 1337; 

 //Next create a ServerSocket on that port
ServerSocket socket = new ServerSocket(port);

//Create a new Server Manager with the socket and start listening
TcpServerManager manager = new TcpServerManager(socket);

If you want all your packets to be encrypted using an SSL connection, simple swap out the ServerSocket for an encrypted one:

//First, select the port that you want to listen o
int port = 1337;

//Use the static generateServerSocket(int) from TcpSocketFactory to automatically generate an SSLServerSocket with default settings. If you would like to use a different encryption, you can use your own socket 
SSLServerSocket socket = TcpSocketFactory.generateServerSocket(port);

//Create a new Server Manager with the socket
TcpServerManager manager = new TcpServerManager(socket);

Clone this wiki locally