服务器代码主动拒绝连接 Udacity 的自动驾驶汽车模拟器(端口 4567)

Server code actively refuses to connect with Udacity's Self Driving Car Simulator (Port 4567)

所以,我目前正在试验 Udacity 的自动驾驶汽车模拟器 (simulator),但是当 运行 drive.py 和模拟器文件时,连接永远不会建立 - 它只是说“已接受”,而不是实际连接。当我查看模拟器的输出日志时,我发现了以下内容:

|Fatal|WebSocket.acceptException|System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it.
                      
                        at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP, Boolean requireSocketPolicy) [0x00000] in <filename unknown>:0 
                        at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00000] in <filename unknown>:0 
                        at System.Net.Sockets.TcpClient.Connect (System.Net.IPEndPoint remote_end_point) [0x00000] in <filename unknown>:0 
                        at System.Net.Sockets.TcpClient.Connect (System.Net.IPAddress[] ipAddresses, Int32 port) [0x00000] in <filename unknown>:0 

每次尝试建立连接时都会出现此错误。这是服务器端的代码(drive.py 文件)

import base64 #for lossless encoding transfer
from datetime import datetime #to set frame timestamp
import os #write + read files
import numpy as np
import shutil
import socketio #server
from flask import Flask #framework for web devices
from io import BytesIO #manipulate string and byte data in memory
import eventlet
import eventlet.wsgi 
import cv2

import tensorflow as tf
import keras
from keras.models import load_model
from PIL import Image



height = 320
width = 160     

def resize(image):
    return cv2.resize(image, (width, height), cv2.INTER_AREA)

#server init
sio = socketio.Server(always_connect = True )
#flask web app
application = Flask(__name__)

#init empty model and image array
net = None
image_array_before = None

#Speed limits
max_speed = 30
min_speed = 10

speed_limit = max_speed

#Server event handler
@sio.on('telemetry')
def telemetry(sid, data):

    if data:
        steering_angle = float(data["steering_angle"])
        throttle = float(data["throttle"])
        speed = float(data["speed"])    
        image = Image.open(BytesIO(base64.b64decode(data["image"])))
        
        #save frame
        timestamp = datetime.utcnow().strftime('%Y_%m_%d_%H_%M_%S_%f')[:-3]
        image_filename = os.path.join(r'path', timestamp)
        image.save('{}.jpg'.format(image_filename))
        
        try:
            image = np.asarray(image)
            image = resize(image)
            image = np.array([image])

            steering_angle = float(net.predict(image))

            global speed_limit
            if speed > speed_limit:   
                speed_limit = min_speed
            else:
                speed_limit = max_speed
            throttle = (1.0 - steering_angle**2 - (speed/speed_limit)**2)

            print ('{} {} {}'.format(steering_angle, throttle, speed))
            send_control(steering_angle, throttle)

        except Exception as e:
            print (e)

    else:
        
        sio.emit('manual', data={}, skip_sid = True)

@sio.on('connect')
def connect(sid, environ):
    print("connect ", sid)
    send_control(0,0) 

def send_control(steering_angle, throttle):
    sio.emit(
        "steer",
        data = {
            "steering_angle": steering_angle.__str__(),
            "throttle": throttle.__str__()
        },
        skip_sid = True)

if __name__ == "__main__":
    net = load_model('path')
    application = socketio.Middleware(sio, application)
    #deploy
    eventlet.wsgi.server(eventlet.listen(('localhost', 4567)), application)

这是 drive.py 文件的输出日志。如您所见,它说已接受但之后不打印连接或传输数据:

enter code here
2021-01-10 15:07:27.659254: W 

tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2021-01-10 15:07:27.668272: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2021-01-10 15:07:56.969613: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set
2021-01-10 15:07:56.998282: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'nvcuda.dll'; dlerror: nvcuda.dll not found
2021-01-10 15:07:57.271013: W tensorflow/stream_executor/cuda/cuda_driver.cc:326] failed call to cuInit: UNKNOWN ERROR (303)
2021-01-10 15:07:57.292101: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: LAPTOP-D2EPGUQF
2021-01-10 15:07:57.390264: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: LAPTOP-D2EPGUQF
2021-01-10 15:07:57.548306: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-01-10 15:07:57.998352: I tensorflow/compiler/jit/xla_gpu_device.cc:99] Not creating XLA devices, tf_xla_enable_xla_devices not set
(2056) wsgi starting up on http://127.0.0.1:4567
(2056) accepted ('127.0.0.1', 52432)

我试图通过禁用防火墙来修复它,但无济于事。知道可能出什么问题了吗?谢谢!

尝试将 python-engineio 版本降级到 3.13.2,将 python-socketio 降级到 4.6.1。

我已经安装了python-engineio 3.13.2 版和python-socketio 4.6.1 版。它已经解决了这个问题。