send and recieve message with myself (python socket )

# socket server
import socket
sk = socket.socket()
sk.bind(("127.0.0.1",8082))
sk.listen()
conn, addr = sk.accept()
message = conn.recv(1024)
print(message)
conn.send(b"hello, world")
conn.close()
sk.close()

#socket client
import socket
sk = socket.socket()
sk.connect(("127.0.0.1",8082))
sk.send(b"hello you ")
message = sk.recv(1024)
print(message)
sk.close()

sorry about having no annotation for every code

if we run the programme in one IDLE, we will have error such as ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。

so i seek help on internet , the solution of the problem is to open two IDLE , and the problem will be solved.

 

posted @ 2019-09-28 00:05  看星星的派大星  阅读(293)  评论(0编辑  收藏  举报