这是我的代码:
def Serveur():
import socket
today = datetime.date.today()
datename = str(today) + '.txt'
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = "192.168.1.245"
port = 8000
print (host)
print (port)
serversocket.bind((host, port))
serversocket.listen(5)
while True:
(clientsocket, address) = serversocket.accept()
print ("Connection Reussie")
data = clientsocket.recv(1024).decode()
print (data) + " RECU PAR ETHERNET"
try:
ver_file = open(datename, "r")
for line in ver_file:
if data in line:
filtre = line[-13:]
print filtre + "MATCH TROUVE"
resultat = str(filtre)
except:
print ("Pas de match de produit captures aujourdhui")
try:
filtre_file = open("produit.txt", "r")
for line in filtre_file:
if resultat in line:
convoyeur = line[-2:]
print convoyeur
except:
print ("Erreur")
(对不起,如果缩进是坏的,当我粘贴它时它搞砸了:() 所以我的问题是,我的str护士根本不打印!我不知道它有什么问题!
收到的数据变量示例是123456789012(以太网条形码扫描器上的12个字符条形码)
produit.txt中一行的示例是:
123456789012 A
(字母A表示盒子需要放在传送带上)