@Override
    public void run()
    {
        this.window.setNetworkStatus(NetworkStatus.WAITING_CONNECTION);
        this.openSocket();


        this.networkUI.setVisible(true);
        this.networkUI.addMessageListener(this);
        this.addMessageListener(this.networkUI);
        this.window.setNetworkStatus(NetworkStatus.CONNECTED);
        GameController controller = GameController.getInstance();
        controller.launch();
        try
        {
            String line;
            while ( this.socket.isConnected() )
            {
                line = this.input.readUTF();
                if ( line.startsWith("MOVE") )
                {
                    Move move = null;
                    try {
                        move = (Move) this.input.readObject();
                    } catch (ClassNotFoundException ex) {
                        Logger.getLogger(NetworkController.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    controller.doMove(move);
                    this.window.unlock();
                }
                else if(line.startsWith("MSG "))
                {
                    for ( MessageListener l : this.listeners )
                        l.newMessage(line.substring(4));
                }
                else if(line.startsWith("BYE"))
                {
                    this.window.setNetworkStatus(NetworkStatus.QUIT);
                }
            }
        }
        catch (IOException ex)
        {
            Logger.getLogger(NetworkController.class.getName()).log(Level.SEVERE, null, ex);
            this.window.setNetworkStatus(NetworkStatus.CONNECTION_ERROR);
        }
    }