0
當我下面在同一無線網絡上運行的Python兩臺計算機之間的progrem,我得到了一個錯誤:爲什麼在python中會出現「Errno 10057 socket error」?
Traceback (most recent call last):
File "Server.EX.py", line 10, in <module>
des1 = s.recv(1024)
socket.error: [Errno 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
Server.py一臺計算機上運行程序:
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((///Computer 1 IP///, 1729))
s.listen(1)
conn, address = s.accept()
print("Connection started.Enter 0 to finish connection.")
des1 = 1
while des1 != 0:
des1 = s.recv(1024)
print(des1)
conn.send(raw_input("SERVER: "))
conn.close()
s.close()
程序客戶端的.py運行在第二臺計算機上:
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((///Computer 1 IP///, 1729))
print("Connection started. Enter 0 to finish connection.")
des1 = 1
while des1 != 0:
s.send(raw_input("CLIENT: "))
des1 = s.recv(1024)
print(des1)
s.close()
有人可以幫助我與討好( - :
*注意///計算機1 IP ///是實際的IPv4地址
改變了它感謝,但現在有這樣的問題: socket.error:[錯誤10048]每個套接字地址 (協議/網絡地址/端口)通常允許之一使用 –
一個特定的地址/端口組合是在套接字關閉後考慮使用一段時間,以處理可能到達的任何滯留的網絡流量。在創建套接字後立即將's.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)'關閉以關閉此功能。 – jasonharper