Created: 2012-03-22 06:33
Updated: 2013-06-15 21:31
License: other



StringServer is a Java library that provides a clean and simple API for building string-based TCP servers, such as for supporting dumb telnet clients, or serving content with simple protocols like HTTP.


StringServer is derived from the excellent KryoNet library, and is released under the New BSD License. See the LICENSE file for details.


First, create a class implementing the Listener interface, specifying what the server should do when a client connects, disconnects, and sends data:

import org.peak15.stringserver.Connection;
import org.peak15.stringserver.Listener;

public class ExampleListener implements Listener {
	public void connected(Connection connection) {
		MainClass.server.sendToAll(connection.toString() + " has connected.");

	public void disconnected(Connection connection) {
		MainClass.server.sendToAll(connection.toString() + " has disconnected.");

	public void received(Connection connection, String string) {
		MainClass.server.sendToAllExcept(, connection.toString() + " says: " + string);
		MainClass.server.sendTo(, "Your message has been broadcasted.");

Now, create a server object using your listener, start it, and bind it to a port.

import org.peak15.stringserver.StringServer;

public class MainClass {
	public static StringServer server;
	public static void main(String[] args) {
		server = new StringServer(new ExampleListener());

And that's it!

Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more