How do I set the packet size when using recvfrom()?
I am trying to capture tcp packets using a Raspberry Pi Model B. I have a python program that uses recvfrom to capture the packets and write them to a .dat file. To be compatible with the matlab code I wrote for post-processing the data. I need size (bytes) of the file to yield an integer value when divided by the packet size (in this case 8568 bytes). Is this possible? If so how do I do this?
Also I am having to shutdown and power back up the tcp source every time I run the code in order to get the recvfrom function to work. I want this to stop, do I need to add a command to clear the port at the beginning or end of the code?
while t < 5:
time.sleep(1)
t+=1
print t
i=str(t)
f=open('test_' + i ,'wb')
radar=s.recvfrom(8568)
data=str(radar)
f.write(data)
print radar
if radar == 0:
print 'no packets'
if radar != 0:
print radar
f.close() s.close()