如何解决服务器代码主动拒绝连接Udacity的自动驾驶汽车模拟器端口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。它已经解决了这个问题。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。