Skip to content

Commit

Permalink
- Refactored to indicate current sockets are TCP specific
Browse files Browse the repository at this point in the history
- Simplified many steps by using higher-level APIs
- Added some comments and changed README
  • Loading branch information
maxlou05 committed Sep 1, 2024
1 parent cef5ce0 commit 08c1a2f
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 457 deletions.
14 changes: 0 additions & 14 deletions network/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Network
<<<<<<< HEAD
This module facilitates communication over TCP and UDP.

## Testing
Expand Down Expand Up @@ -30,16 +29,3 @@ This process repeats until all test messages are sent.

*Note: UDP does not guarantee that data is sent or is not corrupted.
It is a connectionless protocol and thus the server cannot send any messages.
=======
To test `client_socket` and `server_socket`, we will set up a socket server that listens for image byte data from a sender.

Run the test scripts in the following order:

1. `test_receiver.py`
2. `test_sender.py`

`test_receiver.py` will start a socket server listening on `127.0.0.1:8080`. `test_sender.py` will first encode each image returned from `get_images`, then send the raw byte data to the server.

The main loop expects a response from the server, consisting of the original image, data before continuing to the next image. The asserted condition in the main loop tests for equality between the image byte data that was sent to the server, and the byte data that was received, ensuring data integrity.

>>>>>>> 8c58ed6 (Refactor pytest into sender and receiver scripts)
1 change: 0 additions & 1 deletion network/modules/TCP/server_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def __init__(self, class_private_create_key: object, socket_instance: socket.soc
"""
Private constructor, use create() method.
"""

assert class_private_create_key is TcpServerSocket.__create_key, "Use create() method"

super().__init__(socket_instance=socket_instance)
Expand Down
5 changes: 0 additions & 5 deletions network/modules/TCP/socket_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def __init__(self, socket_instance: socket.socket) -> None:
instance: socket.socket
For initializing Socket with an existing socket object.
"""

self.__socket = socket_instance

def send(self, data: bytes) -> bool:
Expand All @@ -32,7 +31,6 @@ def send(self, data: bytes) -> bool:
-------
bool: If the data was sent successfully.
"""

try:
self.__socket.sendall(data)
except socket.error as e:
Expand Down Expand Up @@ -82,7 +80,6 @@ def close(self) -> bool:
-------
bool: If the socket was closed successfully.
"""

try:
self.__socket.close()
except socket.error as e:
Expand All @@ -100,12 +97,10 @@ def address(self) -> "tuple[str, int]":
tuple[str, int]
The address in the format (ip address, port).
"""

return self.__socket.getsockname()

def get_socket(self) -> socket.socket:
"""
Getter for the underlying socket objet.
"""

return self.__socket
93 changes: 0 additions & 93 deletions network/modules/client_socket.py

This file was deleted.

117 changes: 0 additions & 117 deletions network/modules/server_socket.py

This file was deleted.

108 changes: 0 additions & 108 deletions network/modules/socket_wrapper.py

This file was deleted.

Loading

0 comments on commit 08c1a2f

Please sign in to comment.