public void run() {
        if (null == socket)
            return;

        DataInputStream input = null;
        DataOutputStream output = null;

        if (DEBUG) {
            System.out.println("Client connected from "
                    + socket.getRemoteSocketAddress());
        }
        
        try {
            input = new DataInputStream(socket.getInputStream());
            output = new DataOutputStream(socket.getOutputStream());

            // read the message length
            int msgLen = input.readInt();
            
            // create a buffer
            byte[] data = new byte[msgLen];
            // read the entire message (blocks until complete)
            input.readFully(data);

            if (data.length < 1) {
                throw new Exception("Client did not send data.");
            } 
            
            // now convert the raw bytes to utf-8
            String tmp = new String(data, "UTF-8");
            StringReader reader = new StringReader(tmp);
            
            // get the realisation
            String result = doRealisation(reader).trim();
            
            // convert the string to raw bytes
            byte[] tmp2 = result.getBytes("UTF-8");
            
            // write the length
            output.writeInt(tmp2.length);
            // write the data
            output.write(tmp2);
            
            if (DEBUG) {
                String text = "The following realisation was sent to client:";
                System.out.println(text + "\n\t" + result);
            }
            
        } catch (Exception e) {
            e.printStackTrace();
            try {
                // attempt to send the error message to the client
                byte[] tmp = ("Exception: " + e.getMessage()).getBytes("UTF-8");
                output.writeInt(tmp.length);
                output.write(tmp);
            } catch (IOException e1) {
            }
        } catch (XMLRealiserException e) {
            e.printStackTrace();
            try {
                // attempt to send the error message to the client
                byte[] tmp = ("Exception: " + e.getMessage()).getBytes("UTF-8");
                output.writeInt(tmp.length);
                output.write(tmp);
            } catch (IOException e1) {
            }
        } finally {
            try {
                socket.close();
                socket = null;
            } catch (IOException e) {
                System.err.println("Could not close client socket!");
            }
        }
    }