标签:close sock tin not end flush connect tput 程序
from socket import *
from time import ctime
import serial
import time
ser = serial.Serial("/dev/ttyACM0",9600)
ser.flushInput()
ser.flushOutput()
HOST=‘‘
PORT = 6666
BUFSIZE=1024;
ADDR=(HOST,PORT)
tcpSrvSock=socket(AF_INET,SOCK_STREAM)
tcpSrvSock.bind(ADDR)
tcpSrvSock.listen(5)
while True:
print ‘waiting for connection...‘
tcpCliSock,addr = tcpSrvSock.accept()
print ‘...connected from: ‘,addr
while True:
data = tcpCliSock.recv(BUFSIZE)
if not data:
#tcpCliSock.send(‘[%s]%s‘%(ctime(),data))
print[ctime()],‘:‘,data
if data==‘q‘:
print"funExit()"
break
ser.write(data)
tcpCliSock.close()
tcpSrvSock.close()
标签:close sock tin not end flush connect tput 程序
原文地址:http://www.cnblogs.com/123talents/p/7522839.html