码迷,mamicode.com
首页 > 编程语言 > 详细

send and recieve message with myself (python socket )

时间:2019-09-28 01:25:23      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:list   ram   send   open   bin   print   solution   ble   accept   

# 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 )

标签:list   ram   send   open   bin   print   solution   ble   accept   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!