Hi Bary,
Thanks again! The code was a bit messy. I first tried this (socketserver.StreamRequestHandler):
def handle(self):
global doVerbose
global databuffer
# self.rfile is a file-like object created by the handler;
# we can now use e.g. readline() instead of raw recv() calls
self.data = self.rfile.readline().strip()
#print("{} wrote:".format(self.client_address))
#Decode syslog entry
It has a build in readline, working fine, but missing substantial lines. All lines the client sends have the format:
datetime type car=“hhh” size=“” data=“” line=“”\n
NetCat recieves all ok, not missing any line.
So I thought, maybe “rfile.readline()” has a bug, then tried
(socketserver.BaseRequestHandler):
def handle(self):
# self.request is the TCP socket connected to the client
self.data = self.request.recv(1024).strip()
print("{} wrote:".format(self.client_address[0]))
print(self.data)
# just send back the same data, but upper-cased
# self.request.sendall(self.data.upper())
#
#not used/not working because fixed recv
But because it has a fixed buffer I receive the lines like:
datetime type car=“hhh” size=“” data=“” line=“”\ndatetime type car="hh
So data is missing. My thought then was something like this:
def handle(self):
ready = false
buffer = ''
while not ready:
self.data = self.request.recv(1)
if data:
self.data = self.data.decode('utf-8')
buffer = buffer + self.data
if self.data == "\n":
ready= true
result where lines like
d
d
d
d
(so every time only the “d” from
datetime type car=“hhh” size=“” data=“” line=“”\n)
(first character)
Now I am stuck, seems
while not ready:
self.data = self.request.recv(1)
using a loop is not possible in socketserver.BaseRequestHandler “handle”
The strip() is only used in:
self.rfile.readline().strip()
Which already did the “readline”… but is “eating” lines.
Any other suggestions?