OSError:[WinError 10057]无法通过套接字发送任何内容

时间:2018-09-26 18:52:38

标签: python python-3.x sockets

为什么会导致错误?

import socket


HOST = '127.0.0.1'
PORT = 4444
ADDR = (HOST,PORT)
BUFSIZE = 4096

serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

serv.bind(ADDR)
serv.listen(5)

while True:
  conn, addr = serv.accept()
  print ('client connected ... '), addr
  lol = "Hey".encode()
  serv.send(lol)

客户:

import socket

HOST = '127.0.0.1'
PORT = 4444
ADDR = (HOST,PORT)
BUFSIZE = 4096

client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(ADDR)
while True:
orden = client.recv(4096).decode()
print(orden)

错误消息如下:

  

OSError:[WinError 10057]没有发送或接收数据的请求   允许,因为未连接套接字,并且没有地址   通过sendto调用在数据报套接字中发送时提供。

0 个答案:

没有答案