QUIC Protocol Implementation 1.0
A Python implementation of the QUIC (Quick UDP Internet Connections) protocol.
Loading...
Searching...
No Matches
sender.py
Go to the documentation of this file.
1"""
2@file sender.py
3@brief Sender implementation for QUIC protocol.
4@details Sets up a QUIC connection as a sender, creates streams,
5 adds file data to the streams, and initiates sending.
6"""
7
8from constants import Constants
9from quic import (QuicConnection)
10import os
11
12
14 """
15 @brief Checks if a file exists at the current directory and creates it if necessary.
16
17 @details .
18 """
19 if not os.path.exists(Constants.FILE_PATH):
20 with open(Constants.FILE_PATH, 'wb') as file:
21 file.write(b'I' * (Constants.FILE_SIZE * Constants.KILO))
22
23
24def main():
25 """
26 @brief Main function that initializes and runs the sender.
27
28 @details Creates a file if needed, sets up a QUIC connection,
29 creates streams, adds file data, and starts sending.
30 """
31 set_file()
32 quic_connection = QuicConnection(Constants.CONNECTION_ID_SENDER, Constants.ADDR_SENDER, Constants.ADDR_RECEIVER)
33 # Add streams for the files
34 streams = []
35 for i in range(Constants.MAX_STREAMS):
36 streams.append(quic_connection.get_stream(Constants.CONNECTION_ID_SENDER, Constants.UNIDI).get_stream_id())
37 # Add files to the streams
38 for stream in streams:
39 quic_connection.add_file_to_stream(stream, Constants.FILE_PATH)
40 # Start sending
41 quic_connection.send_packets()
42
43
44if __name__ == '__main__':
45 main()
main()
Definition sender.py:24
set_file()
Definition sender.py:13