我的设置是我在本地计算机上运行python socket.io客户端,并在GCP实例上运行服务器。我正在使用基本的socket.io教程代码。问题是客户端将连接到实例,但无法发出。这是客户端和服务器片段。
http_client.py
import socketio
client = socketio.Client()
@client.event
def connect():
print('Client: connected')
@client.event
def disconnect():
print('Client: disconnected')
@client.event
def basicReply():
print(f"From Server: basic reply")
if __name__ == '__main__':
client.connect("http://35.229.56.147:80") # ephemeral IP
client.emit('basicMessage')
client.sleep(2)
client.disconnect()
http_server.py
import socketio
server = socketio.Server()
wsgi_app = socketio.WSGIApp(server)
@server.event
def connect(sid, environ):
print(f"Server: connected {sid[:6]}")
@server.event
def disconnect(sid):
print(f"Server: disconnected {sid[:6]}")
@server.event
def basicMessage(sid):
print(f"From client: basic message")
server.emit('basicReply')
我正在使用2个不同的实例来解释此问题。第一个是具有GPU的常规Compute Engine VM(使用python 3.6)。第二个是Deep Learning VM(使用我安装的python 3.8)。对于常规VM,http通信正常运行。但是对于深度学习,客户端可以连接但不能发出信号。
客户端连接到常规Compute Engine
(v2) C:\Projects\MicroServer\CodeBase\server>python http_client.py
Client: connected
From Server: basic reply
常规Compute Engine上的服务器
philip@pose:~/codebase/server$ sudo gunicorn3 --bind 0.0.0.0:80 http_server:wsgi_app
[2020-04-23 14:41:12 +0000] [3076] [INFO] Starting gunicorn 19.7.1
[2020-04-23 14:41:12 +0000] [3076] [INFO] Listening at: http://0.0.0.0:80 (3076)
[2020-04-23 14:41:12 +0000] [3076] [INFO] Using worker: sync
[2020-04-23 14:41:12 +0000] [3079] [INFO] Booting worker with pid: 3079
Server: connected 06459d
From client: basic message
[2020-04-23 14:41:46 +0000] [3076] [CRITICAL] WORKER TIMEOUT (pid:3079)
[2020-04-23 14:41:46 +0000] [3079] [INFO] Worker exiting (pid: 3079)
[2020-04-23 14:41:47 +0000] [3097] [INFO] Booting worker with pid: 3097
客户端连接到深度学习VM
(v2) C:\Projects\MicroServer\CodeBase\server>python http_client.py
Client: connected
深度学习VM上的服务器
philip@posekeypoints-deb-vm:~/codebase/server$ sudo gunicorn --bind 0.0.0.0:80 http_server:wsgi_app
[2020-04-23 14:47:01 +0000] [2325] [INFO] Starting gunicorn 20.0.4
[2020-04-23 14:47:01 +0000] [2325] [INFO] Listening at: http://0.0.0.0:80 (2325)
[2020-04-23 14:47:01 +0000] [2325] [INFO] Using worker: sync
[2020-04-23 14:47:01 +0000] [2327] [INFO] Booting worker with pid: 2327
Server: connected 81a8d0
[2020-04-23 14:47:36 +0000] [2325] [CRITICAL] WORKER TIMEOUT (pid:2327)
[2020-04-23 14:47:36 +0000] [2327] [INFO] Worker exiting (pid: 2327)
[2020-04-23 14:47:37 +0000] [2342] [INFO] Booting worker with pid: 2342
如您所见,客户端连接但在深度学习服务器上不发光。代码正在运行,服务器在其实例上运行,并且防火墙规则设置为允许http:80。为什么它在深度学习VM上不起作用?