所以我正在尝试从客户端程序向服务器程序发送消息。但是,在我开始写这个问题之前,这个弹出窗口就弹出了:
Traceback (most recent call last):
File "C:\Users\falco\Desktop\socket.py", line 24, in <module>
incoming_mesg = s.recvfrom(40595)
OSError: [WinError 10057] A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied
这是我的客户代码:
#imports
import socket
import sys
import time
s = socket.socket()
status = ""
server = '10.0.0.66' #must be an ip or a hostcode
server_ip = socket.gethostbyname(server) #finds the ip of the other guy
ip = socket.gethostbyname(socket.gethostname())
print(server_ip+ "\n")
port = 5556 #must be a number that matches the server code
s.connect((server,port))
message = input(">>")
message.encode()
s.sendto(message)
没有错误 这是我的服务器代码:
import socket
import time
import sys
host = socket.gethostname()
s = socket.socket()
ip = socket.gethostbyname(socket.gethostname())
port = 5556
ips = []
names = []
print("host is : " + host)
time.sleep(1)
print("ip is : " + ip)
time.sleep
print("port is : " + str(port))
s.bind((host,port))
print("socket created")
s.listen(5)
(client,(ip2,port))= s.accept()
ips.append(ip2)
print(ip+ " has connected to the server")
message = "hi"
message.encode()
incoming_mesg = s.recvfrom(40595)
我非常乐于解决python 3.6.1问题。 谢谢