码迷,mamicode.com
首页 > 其他好文 > 详细

socket

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

标签:python

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

标签:python

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

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