from AmmosAudioSocketReader import AmmosAudioSocketReader

import math
import os
import socket
from collections import deque

import numpy as np
import scipy.io.wavfile as wavfile

from AmmosGlobalFrameBody import AmmosGlobalFrameBody
from AmmosAudioDataHeader import AmmosAudioDataHeader
from AmmosExtendedAudioDataHeader import AmmosExtendedAudioDataHeader
from AmmosGlobalFrameHeader import AmmosGlobalFrameHeader
from AmmosSingleFrame import AmmosSingleFrame
from AmmosContainer import AmmosContainer


in_socket = socket.socket()
in_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
in_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
in_socket.bind(('127.0.0.1', 12345))
in_socket.listen(1)
conn, _ = in_socket.accept()
print('Connected')

socket_reader = AmmosAudioSocketReader(conn)

print('Reading Frames')
while True:
   socket_reader.read_next_frame()
