tencent-ailab / hok_env

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

WSL2 cannot connect to 127.0.0.1 23432 when the gamecore server is running on Windows #11

Closed Caiderkoujiao closed 1 year ago

Caiderkoujiao commented 1 year ago

First of all, thank you very much for your meaningful work.

Now,WSL2 cannot connect to 127.0.0.1 23432 when the gamecore server is running on Windows.

I'm not sure what's wrong, the gamecore service or WSL2?

1、Start the gamecore server outside wsl2 successfully??

G:\Kaiwu\hok_env_gamecore_20221202\gamecore>gamecore-server.exe server --server-address :23432
[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:   export GIN_MODE=release
 - using code:  gin.SetMode(gin.ReleaseMode)

[GIN-debug] POST   /v1/newGame               --> git.woa.com/hongyangqin/kaiwu-remote-cmd/pkg/server.handler.func1 (4 handlers)
[GIN-debug] POST   /v1/stopGame              --> git.woa.com/hongyangqin/kaiwu-remote-cmd/pkg/server.handler.func1 (4 handlers)
[GIN-debug] POST   /v1/list                  --> git.woa.com/hongyangqin/kaiwu-remote-cmd/pkg/server.handler.func1 (4 handlers)
[GIN-debug] POST   /v1/download              --> git.woa.com/hongyangqin/kaiwu-remote-cmd/pkg/server.getHandler.func1 (4 handlers)
[GIN-debug] POST   /v1/check                 --> git.woa.com/hongyangqin/kaiwu-remote-cmd/pkg/server.handler.func1 (4 handlers)
[GIN-debug] GET    /v1/status                --> git.woa.com/hongyangqin/kaiwu-remote-cmd/pkg/server.Server.Status-fm (4 handlers)
[GIN-debug] POST   /v1/exit                  --> git.woa.com/hongyangqin/kaiwu-remote-cmd/pkg/server.getHandler.func1 (4 handlers)
[GIN-debug] PUT    /v1/token                 --> git.woa.com/hongyangqin/kaiwu-remote-cmd/pkg/server.getHandler.func1 (4 handlers)
[GIN-debug] POST   /v2/newGame               --> git.woa.com/hongyangqin/kaiwu-remote-cmd/pkg/server.getHandler.func1 (4 handlers)
[GIN-debug] POST   /v2/stopGame              --> git.woa.com/hongyangqin/kaiwu-remote-cmd/pkg/server.getHandler.func1 (4 handlers)
[GIN-debug] POST   /v2/exists                --> git.woa.com/hongyangqin/kaiwu-remote-cmd/pkg/server.getHandler.func1 (4 handlers)
time="2022-12-08T19:57:28+08:00" level=info msg="start server" Address=":23432" ApiSvcBaseURL= DisableV2api=false Env=dev GamecoreMgr="map[CallBack:[map[] map[Failed:0 Succeed:0 Total:0] map[] map[SaveRate:0.5 SceneManager:map[ABSDir:G:\\Kaiwu\\hok_env_gamecore_20221202\\gamecore\\scene Lock:map[] MaxABSNum:1000 SceneFile:G:\\Kaiwu\\hok_env_gamecore_20221202\\gamecore\\scene\\scene.json]] map[BackupDir:G:\\Kaiwu\\hok_env_gamecore_20221202\\gamecore\\simulator_output Lock:map[] MaxFileNum:4000] map[]] CoreAssets:G:\\Kaiwu\\hok_env_gamecore_20221202\\gamecore\\core_assets GameStore:map[] Preprocessor:map[remote:map[InitABSFile1v1:G:\\Kaiwu\\hok_env_gamecore_20221202\\gamecore\\scene\\1V1.abs InitABSFile3v3:G:\\Kaiwu\\hok_env_gamecore_20221202\\gamecore\\scene\\3V3.abs InitABSFile5v5:G:\\Kaiwu\\hok_env_gamecore_20221202\\gamecore\\scene\\5V5.abs SimulatorRemoteBin:G:\\Kaiwu\\hok_env_gamecore_20221202\\gamecore\\bin\\sgame_simulator_remote_zmq.exe] remote_repeat:map[Remote:map[InitABSFile1v1:G:\\Kaiwu\\hok_env_gamecore_20221202\\gamecore\\scene\\1V1.abs InitABSFile3v3:G:\\Kaiwu\\hok_env_gamecore_20221202\\gamecore\\scene\\3V3.abs InitABSFile5v5:G:\\Kaiwu\\hok_env_gamecore_20221202\\gamecore\\scene\\5V5.abs SimulatorRemoteBin:G:\\Kaiwu\\hok_env_gamecore_20221202\\gamecore\\bin\\sgame_simulator_remote_zmq.exe] RemoteRate:0.2 Repeat:map[SceneManager:map[ABSDir:G:\\Kaiwu\\hok_env_gamecore_20221202\\gamecore\\scene Lock:map[] MaxABSNum:1000 SceneFile:G:\\Kaiwu\\hok_env_gamecore_20221202\\gamecore\\scene\\scene.json] SimulatorRepeatBin:G:\\Kaiwu\\hok_env_gamecore_20221202\\gamecore\\bin\\sgame_simulator_repeated_zmq.exe]] repeat:map[SceneManager:map[ABSDir:G:\\Kaiwu\\hok_env_gamecore_20221202\\gamecore\\scene Lock:map[] MaxABSNum:1000 SceneFile:G:\\Kaiwu\\hok_env_gamecore_20221202\\gamecore\\scene\\scene.json] SimulatorRepeatBin:G:\\Kaiwu\\hok_env_gamecore_20221202\\gamecore\\bin\\sgame_simulator_repeated_zmq.exe]] SimulatorLib:G:\\Kaiwu\\hok_env_gamecore_20221202\\gamecore\\lib]" SGameDir=ai_simulator_remote/ SGameFileName=sgame_simulator_remote_zmq.exe Token=

1

2、Failed to establish a new connection

(py36) max@DESKTOP-P4DU0GV:~/hok_env-master/hok_env/hok/unit_test$ python test_env.py
127.0.0.1:23432 127.0.0.1
load config.dat:  /home/max/hok_env-master/hok_env/hok/env1v1.py
load config...
146[skill=80121]        127.0.0.1       35300   1000
 [('146', '80121'), '127.0.0.1', '35300', '1000'] ./hok/sgame_simulator.conf
146[skill=80121]        127.0.0.1       35301   1000
 [('146', '80121'), '127.0.0.1', '35301', '1000'] ./hok/sgame_simulator.conf
======= test_send_action
try to get first state... [False, False]
Pb2Struct::InitChangeType usedefault=offline
Pb2Struct::InitChangeType change_type=offline
Pb2Struct::InitMainHeroType, no main_hero_type, use default mvp
Traceback (most recent call last):
  File "/home/max/py36/lib/python3.6/site-packages/urllib3/connection.py", line 175, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw
  File "/home/max/py36/lib/python3.6/site-packages/urllib3/util/connection.py", line 95, in create_connection
    raise err
  File "/home/max/py36/lib/python3.6/site-packages/urllib3/util/connection.py", line 85, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/max/py36/lib/python3.6/site-packages/urllib3/connectionpool.py", line 710, in urlopen
    chunked=chunked,
  File "/home/max/py36/lib/python3.6/site-packages/urllib3/connectionpool.py", line 398, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/home/max/py36/lib/python3.6/site-packages/urllib3/connection.py", line 239, in request
    super(HTTPConnection, self).request(method, url, body=body, headers=headers)
  File "/usr/lib/python3.6/http/client.py", line 1291, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1337, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1286, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1046, in _send_output
    self.send(msg)
  File "/usr/lib/python3.6/http/client.py", line 984, in send
    self.connect()
  File "/home/max/py36/lib/python3.6/site-packages/urllib3/connection.py", line 205, in connect
    conn = self._new_conn()
  File "/home/max/py36/lib/python3.6/site-packages/urllib3/connection.py", line 187, in _new_conn
    self, "Failed to establish a new connection: %s" % e
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7fbb25f4f7b8>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/max/py36/lib/python3.6/site-packages/requests/adapters.py", line 450, in send
    timeout=timeout
  File "/home/max/py36/lib/python3.6/site-packages/urllib3/connectionpool.py", line 788, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "/home/max/py36/lib/python3.6/site-packages/urllib3/util/retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=23432): Max retries exceeded with url: /v2/stopGame (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fbb25f4f7b8>: Failed to establish a new connection: [Errno 111] Connection refused',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test_env.py", line 124, in <module>
    config_dicts=[{"hero": "diaochan", "skill": "frenzy"} for _ in range(2)],
  File "test_env.py", line 48, in test_send_action
    use_common_ai=common_ai, eval=eval, config_dicts=config_dicts, render=None
  File "/home/max/hok_env-master/hok_env/hok/env1v1.py", line 716, in reset
    self.game_launcher.start(config_dicts, common_config)
  File "/home/max/hok_env-master/hok_env/hok/gamecore_utils.py", line 438, in start
    self.remote_gc_proc.remote_stop()
  File "/home/max/hok_env-master/hok_env/hok/gamecore_utils.py", line 301, in remote_stop
    self.launch_server, "stopGame", self.user_token, data, ignore_resp=True
  File "/home/max/hok_env-master/hok_env/hok/gamecore_utils.py", line 272, in send_http_request
    resp = requests.post(url=url, json=data, headers=headers, verify=False)
  File "/home/max/py36/lib/python3.6/site-packages/requests/api.py", line 117, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/home/max/py36/lib/python3.6/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/max/py36/lib/python3.6/site-packages/requests/sessions.py", line 529, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/max/py36/lib/python3.6/site-packages/requests/sessions.py", line 645, in send
    r = adapter.send(request, **kwargs)
  File "/home/max/py36/lib/python3.6/site-packages/requests/adapters.py", line 519, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=23432): Max retries exceeded with url: /v2/stopGame (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fbb25f4f7b8>: Failed to establish a new connection: [Errno 111] Connection refused',))
check game stopped.
[Warning] Check game status error, stop it directly. HTTPConnectionPool(host='127.0.0.1', port=23432): Max retries exceeded with url: /v2/stopGame (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fbb260fc160>: Failed to establish a new connection: [Errno 111] Connection refused',))

I don't know what's wrong, how to solve this problem? How do you configure the environment?

Logan-lxw commented 1 year ago

I also meet the same problem now,so have you sloved this problem now? @Caiderkoujiao

hongyangqin commented 1 year ago

The 127.0.0.1 in wsl is not same with 127.0.0.1 in the windows. You need to use the nameserver of the wsl to access the server process running on windows.

image

See also https://learn.microsoft.com/en-us/windows/wsl/networking

hongyangqin commented 1 year ago

Besides, gamecore-server.exe should be allowed to work on all network interface.

image


You can delete the inbound rule for the gamecore-server.exe in firewall setting to reset the setting before.

image

Logan-lxw commented 1 year ago

I am really thankful for your reply.And I solved some problems with your help.But unfortunately,I meet some new problems now. First,I got the nameserver and connect it with my command telnet.

image

Then I delete the inbound rule as what you tell me to do.But when I start python test_env.py ,there is still some fault there. image

I am looking forward to your reply.Thank you! @@hongyangqin @Caiderkoujiao @tencent-ailab @HIT-jixiyang

Logan-lxw commented 1 year ago

First,I got the nameserver and connect it with my command telnet.

Then I delete the inbound rule as what you tell me to do.But when I start python test_env.py ,there is still some fault there.

I am looking forward to your reply.Thank you! 

------------------ 原始邮件 ------------------ 发件人: "tencent-ailab/hok_env" @.>; 发送时间: 2022年12月20日(星期二) 中午11:17 @.>; @.**@.>; 主题: Re: [tencent-ailab/hok_env] WSL2 cannot connect to 127.0.0.1 23432 when the gamecore server is running on Windows (Issue #11)

In wsl, the 127.0.0.1 in wsl is not same with 127.0.0.1 in the windows. You need to use the nameserver of the wsl to access the server process running on windows.

See also https://learn.microsoft.com/en-us/windows/wsl/networking

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>