I have a function getData
which I want to run continuously in a while True
loop. I don't think something is wrong with the code, but I'm posting a snippet down below. When I run the code I have following strange behavior:
I get the correct Data but only for a certain time. For example I get the following dict
:
{var1: 1290.0, var2: 100000.0, ....}
and after the Time where everything works correct there will be an Output as for example:
{var2: 12e-39, var2:-1213141412343, ...}
The lists I named #listofxy
contains just the names of the parameters e.g
['ControlUnit/1', 'Calc_time(ms)', 'Time', ...]
or for the dtypes
['Int', 'Float', ...]
#Datapoints
is the number of bytes I have to request to get for every variable one value(one package)
The server just sends raw data with a rate of 8000 packages per second(float or Int belongs to the Variable and is decaled in #listofdtypes
). Every package has one value for every variable. My PC has a ethernet connection with the server.
So I do not think something is wrong with the server, because it gives me correct data till a certain time. And if something would be wrong with my data acquisition/code there should be an error much earlier and the error is not at the same time on every run. Also I don't think there is a bitshift, because I use a TCP-protocol which should guarantee this.
I also tested the programm on my laptop and had the same problem. Also an colleague has a programm to get data from my server and runs his programm on linux and he has not that issue. Meanwhile, I think there is something strange with windows(haven't tested it yet on a linux machine), but I don't really have a clue. Does someone have an idea why this could happen??
def getData(self):
dataB = b''
self.vari = {key: [] for key in #listofNames}
data = {key: [] for key in #listofNames2}
# get requested number of data bytes
dataB = dataB + self.sock_data.recv(#Datapoints)
while len(dataB) != #requestedLenght:
# check if requested number of data bytes and actual number of data bytes are the same
dataB = dataB + self.sock_data.recv(1)
dt_list = list((x, '<i4' if x == 'Int' else '<f4') for x in #listofdtypes)
for i in range(0, #Datapoints):
for j in range(0, len(#listofNames)):
"""
some code to decode the bytes with a numpy.frombuffer function
"""
for j in range(0, len(#listofNames)):
data[#listofNames[j] = self.vari[#listofNames[j]]
return data
question from:
https://stackoverflow.com/questions/66068468/strange-behaviour-of-my-tcp-socket-connectionget-wrong-data-after-a-some-time 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…