首页 > 编程语言 > 详细

send and recieve message with myself (python socket )

时间:2019-09-28 10:20:27      阅读:83      评论:0      收藏:0      [点我收藏+]
# 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.

 

send and recieve message with myself (python socket )

原文:https://www.cnblogs.com/zijidefengge/p/11601096.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!