title: Server code actively refuses to connect with Udacity's Self Driving Car Simulator (Port 4567)
body: <p>So, I'm currently experimenting with Udacity's self driving car simulator (<a href="https://github.com/udacity/self-driving-car-sim" rel="nofollow noreferrer">simulator</a>), but when running the drive.py and simulator files, the connection is never established - it simply says &quot;accepeted&quot;, rather than actually connecting. When I looked at the output log for the simulator, here's what I found:</p>
  <pre><code>|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 &lt;filename unknown&gt;:0 
                          at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00000] in &lt;filename unknown&gt;:0 
                          at System.Net.Sockets.TcpClient.Connect (System.Net.IPEndPoint remote_end_point) [0x00000] in &lt;filename unknown&gt;:0 
                          at System.Net.Sockets.TcpClient.Connect (System.Net.IPAddress[] ipAddresses, Int32 port) [0x00000] in &lt;filename unknown&gt;:0 
  </code></pre>
  <p>This error happens every time I try and establish a connection. Here's the code on the server side (drive.py file)</p>
  <pre><code>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[&quot;steering_angle&quot;])
          throttle = float(data[&quot;throttle&quot;])
          speed = float(data[&quot;speed&quot;])    
          image = Image.open(BytesIO(base64.b64decode(data[&quot;image&quot;])))
          
          #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 &gt; 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(&quot;connect &quot;, sid)
      send_control(0,0) 
  
  def send_control(steering_angle, throttle):
      sio.emit(
          &quot;steer&quot;,
          data = {
              &quot;steering_angle&quot;: steering_angle.__str__(),
              &quot;throttle&quot;: throttle.__str__()
          },
          skip_sid = True)
  
  if __name__ == &quot;__main__&quot;:
      net = load_model('path')
      application = socketio.Middleware(sio, application)
      #deploy
      eventlet.wsgi.server(eventlet.listen(('localhost', 4567)), application)
  </code></pre>
  <p>Here's the output log for the drive.py file. As you can see, it says accepted but doesn't print connected or transmit data after that:</p>
  <pre><code>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)
  </code></pre>
  <p>I've tried to fix it via disabling the firewall, but to no avail. Any idea what might be wrong? Thanks!</p>