#external_caller.py
import socket
import time


def connect():
    caller_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    caller_socket.connect(('localhost', 12345))
    caller_socket.send("CALLER".encode())
    print("Connected to GSM simulator as CALLER")
    time.sleep(2)  # Wait 2 seconds for receiver to connect

    for i in range(5):
        message = f"Audio packet {i + 1}"
        caller_socket.send(message.encode())
        print(f"Sent: {message}")
        time.sleep(1)

    caller_socket.send("CALL_END".encode())
    print("Call ended.")
    caller_socket.close()

if __name__ == "__main__":
    connect()