Python Socket:WinError 10022

时间:2015-04-02 20:02:08

标签: python sockets python-3.x pickle recvfrom

几年前,我编写了一个与Python 3聊天的程序,在Windows和Mac上一切正常,直到现在。此函数在另一个脚本中执行:

import socket
import pickle

def get(sock):
    data, addr = sock.recvfrom(1024)
    data = pickle.loads(data)           #to convert data back to a dictionary
    return data, addr

在Mac上,这仍然可以正常工作。但Windows抛出错误:

File "C:\Users\...\network.py", line 15, in get
data, addr = sock.recvfrom(1024)
OSError: [WinError 10022] An invalid argument was supplied

问题是什么?

编辑:

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

1 个答案:

答案 0 :(得分:1)

我认为你必须在调用sock.recvfrom(1024)之前绑定到套接字。

sock.bind((YOUR_IP, PORT))