首页 > 代码库 > python socket
python socket
#Server
import socket
HOST = ‘‘
PORT = 51234
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind((HOST,PORT))
s.listen(1)
conn,addr = s.accept()
print ‘Connected by‘, addr
while True:
data = http://www.mamicode.com/conn.recv(1024)
print ‘received:‘,data
if not data:break
conn.sendall(data)
conn.close()
---------------------------------
#client
import socket
HOST = ‘10.10.1.21‘
PORT = 51234
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
#s.bind((HOST,PORT))
s.connect((HOST,PORT))
s.sendall("Hello, world!!!")
data = http://www.mamicode.com/s.recv(1024)
s.close()
print ‘Received‘,repr(data)
python socket
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。