用Python写Socket通信服务程序合理吗
1个回答
展开全部
# -*- coding: utf-8 -*-
import socket
import threading, time
def tcplink(sock,addr):
print('Accept new connection from %s:%s...' %addr)
sock.send(b'Welcome!')
while True:
data=sock.recv(1024)
time.sleep(1)
if not data or data.decode('utf-8')=='exit':
break
sock.send(('Hello,%s!'% data.decode('utf-8')).encode('utf-8'))
sock.close()
print('Connection from %s:%s closed.' % addr)
s=socket.socket()
import socket
import threading, time
def tcplink(sock,addr):
print('Accept new connection from %s:%s...' %addr)
sock.send(b'Welcome!')
while True:
data=sock.recv(1024)
time.sleep(1)
if not data or data.decode('utf-8')=='exit':
break
sock.send(('Hello,%s!'% data.decode('utf-8')).encode('utf-8'))
sock.close()
print('Connection from %s:%s closed.' % addr)
s=socket.socket()
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询