@Override
    public void onReceive(Object msg) throws Exception {
        System.out.println("TcpServer received:" + msg);
        
        if (msg instanceof Integer) {
            final int port = (Integer) msg;
            startServer(port);
        } else if (msg instanceof Bound) {
            getSender().tell(msg, getSelf());
        } else if (msg instanceof CommandFailed) {
            getContext().stop(getSelf());
        } else if (msg instanceof Connected) {
            final Connected conn = (Connected) msg;
            getSender().tell(conn, getSelf());
            registerCodec(getSender());
        }
    }