python怎么实现tcp通信
答案:2 悬赏:30 手机版
解决时间 2021-12-01 20:56
- 提问者网友:我是女神我骄傲
- 2021-12-01 10:22
python怎么实现tcp通信
最佳答案
- 五星知识达人网友:白昼之月
- 2021-12-01 10:56
服务器端:
#!/usr/bin/env python
import socket
host="localhost"
port=10000
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind((host,port))
s.listen(5)
while 1:
sock,addr=s.accept()
print "got connection form ",sock.getpeername()
data=sock.recv(1024)
if not data:
break
else:
print data
客户端:
#!/usr/bin/env python
import socket
host="localhost"
port=10000
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((host,port))
s.send("hello from client")
s.close()
#!/usr/bin/env python
import socket
host="localhost"
port=10000
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind((host,port))
s.listen(5)
while 1:
sock,addr=s.accept()
print "got connection form ",sock.getpeername()
data=sock.recv(1024)
if not data:
break
else:
print data
客户端:
#!/usr/bin/env python
import socket
host="localhost"
port=10000
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((host,port))
s.send("hello from client")
s.close()
全部回答
- 1楼网友:爱难随人意
- 2021-12-01 11:15
需要编程
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯