如何在群集上运行TCP / IP游戏

时间:2016-05-06 11:19:59

标签: bash shell tcp cluster-computing sungridengine

我写了一个TCP / IP游戏,涉及一个服务器和两个客户,然后他们玩游戏,写一些关于它的统计数据并关闭。 (这是两个AI玩游戏)

我编写了一个打开这三个子脚本的shell脚本。但是,目前没有编写统计数据。由于有时设置阶段(客户端连接到服务器)工作,有时甚至不工作,我认为那些孩子错误地分布在核心上并且无法与服务器通信。 (?)

我一般如何解决这个问题?也许没有tmux?运行SGE,版本6.2u3beta。

这是我的shell脚本:

#!/bin/bash

# This script is supposed to take a json problem instance (name is problemNNNNN.json)
# Then open server with -i problem$SGE_TASK_ID.json -o -p open-port,
# then open two clients with -p open-port.

#$ -S /bin/bash
#$ -m n
#$ -l h_vmem=4G
## Tasks
#$ -t 1-1
#$ -cwd

problem_file=problem$SGE_TASK_ID.json

function find_open_port(){
    # Ports between 49152 - 65535 are usually unused.
    port=$(shuf -i '49152-65535' -n '1')

    # Then check if port is open
    if lsof -Pi :$port -sTCP:LISTEN -t >/dev/null ; then
        find_open_port
    else
        # There is no service currently running on this port
        return $port
    fi
}

find_open_port

tmux new-session -d -s '$SGE_TASK_ID' "python server.py -p $port -i $problem_file"
sleep 1
tmux split-window -v -t '$SGE_TASK_ID' "python client.py -p $port"
sleep 1
tmux split-window -h -t '$SGE_TASK_ID' "python client.py -p $port"

exit

0 个答案:

没有答案
相关问题