使用中的地址python

问题描述 投票:0回答:1

我正在尝试将我的tello edu连接到我的笔记本电脑,但出现错误地址已在使用中

import socket
import threading
import time
import sys

# IP and port of Tello
tello_address = ('192.168.10.1', 8889)

# IP and port of local computer
local_address = ('', 9000)

# Create a UDP connection that we'll send the command to
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

# Bind to the local address and port
sock.bind(local_address)

# Send the message to Tello and allow for a delay in seconds
def send(message):
  # Try to send the message otherwise print the exception
  try:
    sock.sendto(message.encode(), tello_address)
    print("Sending message: " + message)
  except Exception as e:
    print("Error sending: " + str(e))

# Receive the message from Tello
def receive():
  # Continuously loop and listen for incoming messages
  while True:
    # Try to receive the message otherwise print the exception
    try:
      response, ip_address = sock.recvfrom(128)
      print("Received message: " + response.decode(encoding='utf-8'))
    except Exception as e:
      # If there's an error close the socket and break out of the loop
      sock.close()
      print("Error receiving: " + str(e))
      break

# Create and start a listening thread that runs in the background
# This utilizes our receive function and will continuously monitor for incoming messages
receiveThread = threading.Thread(target=receive)
receiveThread.daemon = True
receiveThread.start()

# Tell the user what to do
print('Type in a Tello SDK command and press the enter key. Enter "quit" to exit this program.')

# Loop infinitely waiting for commands or until the user types quit or ctrl-c
while True:

  try:
    # Read keybord input from the user
    if (sys.version_info > (3, 0)):
      # Python 3 compatibility
      message = input('')
    else:
      # Python 2 compatibility
      message = raw_input('')

    # If user types quit then lets exit and close the socket
    if 'quit' in message:
      print("Program exited sucessfully")
      sock.close()
      break

    # Send the command to Tello
    send(message)

  # Handle ctrl-c case to quit and close the socket
  except KeyboardInterrupt as e:
    sock.close()
    break

错误回溯(最近一次通话)在()中1920#绑定到本地地址和端口---> 21 sock.bind(本地地址)2223#将消息发送到Tello,并允许延迟几秒钟]

/ usr / lib / python2.7 / socket.pyc in meth(name,self,* args)226227 def meth(name,self,* args):-> 228 return getattr(self._sock,name)(* args)229_socket方法中的_m为230:

错误:[Errno 98]地址已在使用中

python
1个回答
0
投票

该消息表示还有另一个进程正在监听端口9000。可能是您已经启动了应用程序的一个实例,没有停止它,它仍在运行并阻塞了该端口。当启动另一个实例时,它不能使用该端口。在这种情况下,只需停止先前启动的实例即可。

否则,请检查还有哪些其他应用程序使用此端口并停止它。

或者,使用其他端口。

© www.soinside.com 2019 - 2024. All rights reserved.