首页 > 其他 > 详细

socket

时间:2017-03-10 22:42:43      阅读:229      评论:0      收藏:0      [点我收藏+]

###########################
server端:
import socket
server= socket.socket()

server.bind((‘localhost‘,6969))
server.listen()

print("等电话")
conn,addr=server.accept()
print(conn,addr)
print("来了")
data = conn.recv(1024)
print("recv:",data)
conn.send(data.upper())
server.close()

###########################
client端:

import socket
client = socket.socket()
client.connect((‘localhost‘,6969))

client.send(b"hello world")
data = client.recv(1024)
print("recv:",data)
client.close()

#########################
#########################
client端:
####
import socket
client = socket.socket()
client.connect((‘10.0.0.11‘,6969))
while True:
    msg=input(">>:").strip()
    client.send(msg.encode(‘utf8‘))
    data = client.recv(1024)
    print("recv:", data)

client.close()

####
server端:
####
import socket
server= socket.socket()

server.bind((‘10.0.0.11‘,6969))
server.listen()

print("等电话")
conn,addr=server.accept()
print(conn,addr)
print("来了")
while True:
    data = conn.recv(1024)
    print("recv:", data.decode())
    conn.send(data.upper())
server.close()


socket

原文:http://bujuhandong.blog.51cto.com/1443515/1905248

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