QuickServer empowering protocols



SourceForge.net Logo

QuickStart - Building HelloWorld Server - QuickServer v1.4.5
This Quick Start Guide shows you how to create a multi client "HelloWorld" server application using the QuickServer v1.4.5. [View the latest version of QuickStart Guide]
So lets say our server will interact with the client some thing like this..
C: <open connection>
S: Hello Word!
C: hi
S: You Sent: Hi
C: quit
S: bye
S: <close connection>

So now lets start by writing a command handler that implements this
// HelloWorldCommandHandler.java
package mypackage;

import java.net.*;
import java.io.*;
import org.quickserver.net.server.ClientCommandHandler;
import org.quickserver.net.server.ClientHandler;

public class HelloWorldCommandHandler implements ClientCommandHandler {
	public void gotConnected(ClientHandler handler) 
			throws SocketTimeoutException, IOException {
		System.out.println("Got Client: "+
		handler.sendClientMsg("Hello Word!");

	public void lostConnection(ClientHandler handler) 
			throws IOException {
		System.out.println("Connection lost : " + 
	public void closingConnection(ClientHandler handler) 
			throws IOException {
		System.out.println("Closing connection : " + 

	public void handleCommand(ClientHandler handler, String command) 
			throws SocketTimeoutException, IOException {
		if(command.equals("quit")) {
		} else {
			handler.sendClientMsg("You Sent: "+command);

This class implements the org.quickserver.net.server.ClientCommandHandler interface as required by QuickServer. Rest of the code should be self explanatory (else refer to "Developers Guide").
Now compile this file and make a jar out of it.
set CLASSPATH=c:\QuickServer\dist\QuickServer.jar;%CLASSPATH%;
javac mypackage\*.java
jar cvf helloworld.jar mypackage/*.class

Now we need to write our xml file to tell QuickServer about our server's configuration. Note that writing xml is not required and QuickServer can be started with out one (configurable programmatically), but it just makes it easy to use xml and configure a server. So below is the HelloWorld.xml
	<name>HelloWorld v 0.1</name>



So that's it, we should be ready with our server. Lets start it by giving the following command.
java -jar QuickServer.jar -load HelloWorld.xml
You should see similar output on your screen.
HelloWorld Server
Now you can use any socket communication software like telnet to connect on port 1000 and comunicate with the server that we just built.
Alternatively you may use 'SocketTest' - a java based tool for testing sockets (Download/WebStart from http://sockettest.sourceforge.net/)
Below is the screen shot of a simple test using SocketTest.
Testing on SockeTest
Also below is a code for a simple java client for our HelloWorld server.
// HelloWorldClient.java
package mypackage;

import java.net.*;
import java.io.*;

public class HelloWorldClient {
	public static void main(String args[]) {
		BufferedReader br = null;
		PrintWriter out = null;
		Socket socket = null;
		int port = 1000;

		if(args.length<2) {
			System.err.println("Usage : "+
			"\n HelloWorldClient  ");

		try {
			port = Integer.parseInt(args[1]);
			System.out.print("Connecting.. ");

			socket = new Socket(args[0], port);
			System.out.println("Connected to "+

			br = new BufferedReader(new InputStreamReader(
			out = new PrintWriter(new BufferedWriter(
				new OutputStreamWriter(
					socket.getOutputStream())), true);

			String recData = br.readLine();
			System.out.println("S: "+recData);

			System.out.println("C: Hi");

			recData = br.readLine();
			System.out.println("S: "+recData);

			System.out.println("C: quit");
			recData = br.readLine();
			System.out.println("S: "+recData);

		} catch(Exception e) {
			System.err.println("Error " + e);
		} finally {
			try {
			} catch(Exception er) {
				System.err.println("Error closing: " + er);

Note that in the above QuickStart we receive and send strings that end with newline (\r\n) character. This is known as STRING mode and is the default mode of data exchange. QuickServer supports other modes of data exchange like BYTE, BINARY, OBJECT.
If you like to know about features that come with QuickServer click here.
If you need more detailed explanation on developing server's using QuickServer refer to examples that come with QuickServer and/or Developers Guide and API documentation.