
from nuts import UDPAuthChannel

channel = UDPAuthChannel('secret') # Re-key handling? Load key from file, or mutable struct?
with channel.connect( ('10.0.0.1', 8001) ) as session:
    session.send('Take pic!')
    msg = session.receive()
    num_chunks = int(msg)
    with open('latest_img.jpg', 'wb') as img_fh:
        for i in range(num_chunks):
            chunk = session.receive()
            print('got chunk %d of %d' % (i + 1, num_chunks))
            img_fh.write(chunk)


from nuts import UDPAuthChannel

channel = UDPAuthChannel('secret', timeout=4)
with channel.connect( ('10.0.0.1', 8001) ) as session:
    session.send('Take pic!')
    msg = session.receive()
    num_chunks = int(msg)
    with open('latest_img.jpg', 'wb') as img_fh:
        for i in range(num_chunks):
            chunk = session.receive()
            print('got chunk %d of %d' % (i + 1, num_chunks))
            img_fh.write(chunk)

Set 4s timeout for img client
Set 4s timeout for img client

  
  from nuts import UDPAuthChannel
  
- channel = UDPAuthChannel('secret') # Re-key handling? Load key from file, or mutable struct?
+ channel = UDPAuthChannel('secret', timeout=4)
  with channel.connect( ('10.0.0.1', 8001) ) as session:
      session.send('Take pic!')
      msg = session.receive()
      num_chunks = int(msg)
      with open('latest_img.jpg', 'wb') as img_fh:
          for i in range(num_chunks):
              chunk = session.receive()
              print('got chunk %d of %d' % (i + 1, num_chunks))
              img_fh.write(chunk)
  
Set 4s timeout for img client
## Code Before:

from nuts import UDPAuthChannel

channel = UDPAuthChannel('secret') # Re-key handling? Load key from file, or mutable struct?
with channel.connect( ('10.0.0.1', 8001) ) as session:
    session.send('Take pic!')
    msg = session.receive()
    num_chunks = int(msg)
    with open('latest_img.jpg', 'wb') as img_fh:
        for i in range(num_chunks):
            chunk = session.receive()
            print('got chunk %d of %d' % (i + 1, num_chunks))
            img_fh.write(chunk)

## Instruction:
Set 4s timeout for img client
## Code After:

from nuts import UDPAuthChannel

channel = UDPAuthChannel('secret', timeout=4)
with channel.connect( ('10.0.0.1', 8001) ) as session:
    session.send('Take pic!')
    msg = session.receive()
    num_chunks = int(msg)
    with open('latest_img.jpg', 'wb') as img_fh:
        for i in range(num_chunks):
            chunk = session.receive()
            print('got chunk %d of %d' % (i + 1, num_chunks))
            img_fh.write(chunk)
