public static void runServer(String mapFilename, int port) {
        TMServer server = new TMServer(new File(mapFilename));
        ServerSocket serverConn;
        try
        {
            serverConn = new ServerSocket(port);
            serverConn.setReuseAddress(true);
        }
        catch (IOException ex)
        {
            System.out.println("" + ex);
            serverConn = null;
        }

        if (serverConn == null)
        {
            System.err.println("Cannot listen on specified port");
        }
        else
        {
            new Timer(false).schedule(new TMServerEventDetect(server), 0, 30);
            while (true)
            {
                Socket conn;
                int id = -1;
                try
                {
                    conn = serverConn.accept();
                    for (int i = 0; i != Rule.MAX_TANKS; ++ i)
                    {
                        if (!server.mPlayers[i].mAlive)
                        {
                            id = i;
                            break;
                        }
                    }
                    if (id == -1)
                    {
                        conn.close();
                        continue;
                    }

                    System.err.println("New connection for id " + id);
                    LinkedBlockingQueue<String> inQueue = new LinkedBlockingQueue<String>();
                    LinkedBlockingQueue<String> outQueue = new LinkedBlockingQueue<String>();
						 
                    BufferedWriter writer = new BufferedWriter(
                        new OutputStreamWriter(conn.getOutputStream()));
                    outQueue.put(server.getTime() + " set-id " + id);
                    outQueue.put(server.getTime() + " load " + mapFilename);

                    server.mPlayers[id].mLastMove = -1;
                    server.mPlayers[id].mLastRotate = -1;
                    server.mPlayers[id].mLastShoot = -1;
                    server.mPlayers[id].mBorned = false;
                    server.mPlayers[id].mInQueue = inQueue;
                    server.mPlayers[id].mOutQueue = outQueue;
                    server.mPlayers[id].mAlive = true;

                    new Thread(
                        new TMServerConnectionRecv(
                            server,
                            inQueue,
                            new InputStreamReader(conn.getInputStream()),
                            conn
                            )).start();
                    new Thread(
                        new TMServerConnectionSend(
                            outQueue,
                            new OutputStreamWriter(conn.getOutputStream()),
                            conn
                            )).start();

                }
                catch (Exception ex)
                {
                    System.err.println("connection failed ");
                    ex.printStackTrace();
                    conn = null;
                    continue;
                }
            }
        }
    }