import socket

capture_filename = "./captures/capture.bin"
capture_size = 10*1024*1024

sock  = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(("", 8000))

# capture data
data_size = 0
f = open(capture_filename, "wb")
while data_size <= capture_size:
    data, addr = sock.recvfrom(8192)
    data_size += len(data)
    f.write(data)
f.close()

# split data in jpg files
def split_capture(f):
    c = bytearray()
    while True:
        b = f.read(1048)
        if not b: # end-of-file
            yield data
            return
        c += b
        while True:
            pos = c.find(bytearray(b"\xff\xd9"))
            if pos < 0:
                break
            yield c[:pos]
            c = c[pos + 2:]

for i, capture in enumerate(split_capture(open(capture_filename, 'rb'))):
    f = open("./captures/capture_{}.jpg".format(str(i)), "wb")
    f.write(capture)
    f.close()

@@ -4,15 +4,71 @@
 ort 
-socket%0A
+os%0Aimport subprocess%0Aimport socket%0A%0Acapture_dir = %22./captures/%22
 %0Acap
@@ -88,30 +88,51 @@
  = %22
-./
 capture
-s/capture.bin
+.bin%22%0Ajpg_filename = %22capture_%7B%7D.jpg
 %22%0Aca
@@ -238,16 +238,88 @@
 8000))%0A%0A
+# clean capture_dir%0Asubprocess.call(%5B%22rm%22, %22-rf%22, capture_dir + %22/*%22%5D)%0A%0A
 # captur
@@ -344,24 +344,50 @@
  0%0Af = open(
+os.path.join(capture_dir, 
 capture_file
@@ -390,16 +390,17 @@
 filename
+)
 , %22wb%22)%0A
@@ -940,16 +940,42 @@
 re(open(
+os.path.join(capture_dir, 
 capture_
@@ -982,16 +982,17 @@
 filename
+)
 , 'rb'))
@@ -1011,35 +1011,46 @@
 pen(
-%22./captures/capture_%7B%7D.jpg%22
+os.path.join(capture_dir, jpg_filename
 .for
@@ -1060,16 +1060,17 @@
 (str(i))
+)
 , %22wb%22)%0A

improve test_capture