tencent-ailab / hok_env

Honor of Kings AI Open Environment of Tencent
https://aiarena.tencent.com/aiarena/en/open-gamecore
Apache License 2.0
590 stars 68 forks source link

Connection Error #55

Open nathanyi96 opened 2 months ago

nathanyi96 commented 2 months ago

I launched the GameCore from win11 cmd:

image

Then I did

(wzry-py38) nathan@JanisDesktop:~/hok_env/hok_env/hok/hok1v1/unit_test$ python test_env.py 

But I keep getting this error:

172.20.176.1:23432 127.0.0.1
======= test_send_action
camp_config {'mode': '1v1', 'heroes': [[{'hero_id': 119}], [{'hero_id': 107}]]}
common_ai [False, True]
try to get first state...
Traceback (most recent call last):
  File "/home/nathan/miniconda3/envs/wzry-py38/lib/python3.8/site-packages/urllib3/connectionpool.py", line 793, in urlopen
    response = self._make_request(
  File "/home/nathan/miniconda3/envs/wzry-py38/lib/python3.8/site-packages/urllib3/connectionpool.py", line 537, in _make_request
    response = conn.getresponse()
  File "/home/nathan/miniconda3/envs/wzry-py38/lib/python3.8/site-packages/urllib3/connection.py", line 466, in getresponse
    httplib_response = super().getresponse()
  File "/home/nathan/miniconda3/envs/wzry-py38/lib/python3.8/http/client.py", line 1348, in getresponse
    response.begin()
  File "/home/nathan/miniconda3/envs/wzry-py38/lib/python3.8/http/client.py", line 316, in begin
    version, status, reason = self._read_status()
  File "/home/nathan/miniconda3/envs/wzry-py38/lib/python3.8/http/client.py", line 277, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/home/nathan/miniconda3/envs/wzry-py38/lib/python3.8/socket.py", line 669, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/nathan/miniconda3/envs/wzry-py38/lib/python3.8/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
  File "/home/nathan/miniconda3/envs/wzry-py38/lib/python3.8/site-packages/urllib3/connectionpool.py", line 847, in urlopen
    retries = retries.increment(
  File "/home/nathan/miniconda3/envs/wzry-py38/lib/python3.8/site-packages/urllib3/util/retry.py", line 470, in increment
    raise reraise(type(error), error, _stacktrace)
  File "/home/nathan/miniconda3/envs/wzry-py38/lib/python3.8/site-packages/urllib3/util/util.py", line 38, in reraise
    raise value.with_traceback(tb)
  File "/home/nathan/miniconda3/envs/wzry-py38/lib/python3.8/site-packages/urllib3/connectionpool.py", line 793, in urlopen
    response = self._make_request(
  File "/home/nathan/miniconda3/envs/wzry-py38/lib/python3.8/site-packages/urllib3/connectionpool.py", line 537, in _make_request
    response = conn.getresponse()
  File "/home/nathan/miniconda3/envs/wzry-py38/lib/python3.8/site-packages/urllib3/connection.py", line 466, in getresponse
    httplib_response = super().getresponse()
  File "/home/nathan/miniconda3/envs/wzry-py38/lib/python3.8/http/client.py", line 1348, in getresponse
    response.begin()
  File "/home/nathan/miniconda3/envs/wzry-py38/lib/python3.8/http/client.py", line 316, in begin
    version, status, reason = self._read_status()
  File "/home/nathan/miniconda3/envs/wzry-py38/lib/python3.8/http/client.py", line 277, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/home/nathan/miniconda3/envs/wzry-py38/lib/python3.8/socket.py", line 669, in readinto
    return self._sock.recv_into(b)
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test_env.py", line 111, in <module>
    test_send_action(env, common_ai=[False, True], eval=False, camp_config=camp_config)
  File "test_env.py", line 47, in test_send_action
    obs, reward, done, state = env.reset(
  File "/home/nathan/hok_env/hok_env/hok/hok1v1/env1v1.py", line 638, in reset
    self.game_launcher.start_game(
  File "/home/nathan/hok_env/hok_env/hok/common/gamecore_client.py", line 109, in start_game
    self._send_http_request("newGame", data)
  File "/home/nathan/hok_env/hok_env/hok/common/gamecore_client.py", line 142, in _send_http_request
    resp = requests.post(url=url, json=data, headers=headers, verify=False)
  File "/home/nathan/miniconda3/envs/wzry-py38/lib/python3.8/site-packages/requests/api.py", line 115, in post
    return request("post", url, data=data, json=json, **kwargs)
  File "/home/nathan/miniconda3/envs/wzry-py38/lib/python3.8/site-packages/requests/api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/nathan/miniconda3/envs/wzry-py38/lib/python3.8/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/nathan/miniconda3/envs/wzry-py38/lib/python3.8/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
  File "/home/nathan/miniconda3/envs/wzry-py38/lib/python3.8/site-packages/requests/adapters.py", line 501, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

This is my server config in my WSL2 ~/.bashrc:

export GAMECORE_SERVER_ADDR="172.20.176.1:23432"
export AI_SERVER_ADDR="127.0.0.1"
# 172.20.176.1 is my win11 ip address
nathanyi96 commented 2 months ago

Since I've never done any development on Windows OS, I spent a lot of time on the Env setup on Windows powershell/cmd, wsl setup problems, such as how to run gamecore on windows, how can WSL communicate with the gamecore server running on Windows port 23432.....

It would be very helpful if you guys can post a tutorial video about how to setup the env and show developer how to successfully run the test_env.py

AIyumeng commented 2 months ago

Hello ,I have the same problem with you.How to solve it?Do you have any idea?

nathanyi96 commented 1 month ago

Hello ,I have the same problem with you.How to solve it?Do you have any idea?

Not yet... 😭

Starlight0798 commented 1 month ago

I have the same problem,too. I think the cause is that gamecore fails to send response to WSL2 test bench.Have you already solved this problem?

Starlight0798 commented 1 month ago

I have the same problem,too. I think the cause is that gamecore fails to send response to WSL2 test bench.Have you already solved this problem?

Oh I figure it out.The code in test_env.py:

for i in range(AGENT_NUM):
    addrs.append("tcp://0.0.0.0:{}".format(35150 + i))

But docs give:

docker run -it -p 35300-35400:35300-35400 tencentailab/hok_env:cpu_v2.0.1 bash

It is obvious that agent port range is out of mapping range.I change the command to it:

docker run -it -p 35000-35400:35000-35400 --rm tencentailab/hok_env

And it works.

Here I give all the sequence of the processes:

Start GameCore(on your Win10 or Win11):

gamecore-server.exe server --server-address :23432

Run docker(ensure your WSL2 is already):

docker run -it -p 35000-35400:35000-35400 --rm tencentailab/hok_env

Set env-variable and run python:

cd hok_env/hok/hok1v1/unit_test
export GAMECORE_SERVER_ADDR="host.docker.internal:23432" 
python test_env.py

Then I get what README.md shows. Anyone who comes across this problem can try my method.