Errno 10049:creating UDP 套接字
Errno 10049:creating UDP socket
该代码用于创建客户端 UDP 套接字。不知道怎么回事
# UDPPingerClient.py
from socket import *
serverName = '';
serverPort = 12000;
clientSocket = socket(AF_INET, SOCK_DGRAM)
message = raw_input("Input message:")
clientSocket.sendto(message,(serverName,serverPort))
modifiedMessage, serverAddress = clientSocket.recvfrom(1024)
print(modifiedMessage)
print(serverAddress)
clientSocket.close()
Errno 10049 in line 12
我猜你是根据错误号使用 Windows,根据 Microsoft,Errno 10049 如下:
Cannot assign requested address.
The requested address is not valid in its context. This normally results from an attempt to bind to an address that is not valid for the local computer. This can also result from connect, sendto, WSAConnect, WSAJoinLeaf, or WSASendTo when the remote address or port is not valid for a remote computer (for example, address or port 0).
这可能是由于尝试使用同一个套接字发送和接收造成的。因此,您需要创建两个套接字,一个用于接收信息,一个用于发送信息。
MSDN:
WSAEADDRNOTAVAIL 10049
Cannot assign requested address.
The requested address is not valid in its context. This normally results from an attempt to bind to an address that is not valid for
the local computer. This can also result from connect
, sendto
,
WSAConnect
, WSAJoinLeaf
, or WSASendTo
when the remote address or port
is not valid for a remote computer (for example, address or port 0).
这是因为您试图用空 serverName
调用 sendto
。使用像 'example.com'
、'127.0.0.1'
、'0.0.0.0'
这样的有效地址,它将起作用。
当您在新套接字上调用 sendto
时,它首先尝试将服务器地址和端口转换为系统可用的表示 API。空字符串不是有效地址,您会收到错误消息。
该代码用于创建客户端 UDP 套接字。不知道怎么回事
# UDPPingerClient.py
from socket import *
serverName = '';
serverPort = 12000;
clientSocket = socket(AF_INET, SOCK_DGRAM)
message = raw_input("Input message:")
clientSocket.sendto(message,(serverName,serverPort))
modifiedMessage, serverAddress = clientSocket.recvfrom(1024)
print(modifiedMessage)
print(serverAddress)
clientSocket.close()
Errno 10049 in line 12
我猜你是根据错误号使用 Windows,根据 Microsoft,Errno 10049 如下:
Cannot assign requested address. The requested address is not valid in its context. This normally results from an attempt to bind to an address that is not valid for the local computer. This can also result from connect, sendto, WSAConnect, WSAJoinLeaf, or WSASendTo when the remote address or port is not valid for a remote computer (for example, address or port 0).
这可能是由于尝试使用同一个套接字发送和接收造成的。因此,您需要创建两个套接字,一个用于接收信息,一个用于发送信息。
MSDN:
WSAEADDRNOTAVAIL 10049 Cannot assign requested address.
The requested address is not valid in its context. This normally results from an attempt to bind to an address that is not valid for the local computer. This can also result from
connect
,sendto
,WSAConnect
,WSAJoinLeaf
, orWSASendTo
when the remote address or port is not valid for a remote computer (for example, address or port 0).
这是因为您试图用空 serverName
调用 sendto
。使用像 'example.com'
、'127.0.0.1'
、'0.0.0.0'
这样的有效地址,它将起作用。
当您在新套接字上调用 sendto
时,它首先尝试将服务器地址和端口转换为系统可用的表示 API。空字符串不是有效地址,您会收到错误消息。