Skip to content
Snippets Groups Projects
Commit 3cc1606d authored by hangxie2's avatar hangxie2
Browse files

MP3 CAMERA READY

parent 354b0bdc
No related branches found
No related tags found
1 merge request!11MP3 CAMERA READY
...@@ -8,4 +8,6 @@ exclude = ...@@ -8,4 +8,6 @@ exclude =
./sample_test/src/*.py ./sample_test/src/*.py
per-file-ignores = per-file-ignores =
./mp1/node.py:W291 ./mp1/node.py:W291
./mp3/server.py:F841
import random import random
from constants import SERVER_IDENTIFIER, SERVER_ADDRESS, SERVER_PORT, ENCODING_FORMAT, MSG_LENGTH from constants import SERVER_IDENTIFIER, SERVER_ADDRESS, SERVER_PORT, ENCODING_FORMAT, MSG_LENGTH
from utils import gprint, pprint # from utils import gprint, pprint
import os import os
import sys import sys
import socket import socket
...@@ -37,9 +37,9 @@ def connect(coordinator_info: tuple): ...@@ -37,9 +37,9 @@ def connect(coordinator_info: tuple):
coordinator_port_number = coordinator_info[1][SERVER_PORT] coordinator_port_number = coordinator_info[1][SERVER_PORT]
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
address = (coordinator_ip_address, coordinator_port_number) address = (coordinator_ip_address, coordinator_port_number)
pprint(f'[connect] - client connecting to address {address}') # pprint(f'[connect] - client connecting to address {address}')
client.connect(address) client.connect(address)
pprint(f'[connect] - client connecting to address {address} success!') # pprint(f'[connect] - client connecting to address {address} success!')
return client return client
...@@ -48,17 +48,17 @@ def bind(): ...@@ -48,17 +48,17 @@ def bind():
server.bind(ADDR) server.bind(ADDR)
server.listen() server.listen()
conn, addr = server.accept() conn, addr = server.accept()
gprint(f"[Bind] - Bind to {addr} success!") # gprint(f"[Bind] - Bind to {addr} success!")
return conn return conn
def send_operation(operation_str, socket): def send_operation(operation_str, socket):
msg = operation_str.upper().encode(ENCODING_FORMAT) # todo: upper case msg = operation_str.encode(ENCODING_FORMAT) # todo: upper case
msg_length = len(msg) msg_length = len(msg)
# send_length = str(msg_length).encode(ENCODING_FORMAT) # send_length = str(msg_length).encode(ENCODING_FORMAT)
msg += b' ' * (MSG_LENGTH - msg_length) msg += b' ' * (MSG_LENGTH - msg_length)
# pprint(f'[send_operation] - {locals()}') # pprint(f'[send_operation] - {locals()}')
pprint(f'[send_operation] - msg.length : {len(msg)}') # pprint(f'[send_operation] - msg.length : {len(msg)}')
socket.sendall(msg) socket.sendall(msg)
...@@ -77,10 +77,10 @@ if __name__ == '__main__': ...@@ -77,10 +77,10 @@ if __name__ == '__main__':
coordinator_info = pick_coordinator(servers) coordinator_info = pick_coordinator(servers)
client_to_coordinator_socket = connect(coordinator_info) client_to_coordinator_socket = connect(coordinator_info)
pprint('[client_to_coordinator_socket] CONNECT SUCCESS!') # pprint('[client_to_coordinator_socket] CONNECT SUCCESS!')
# coordinator_to_client_socket = bind() # coordinator_to_client_socket = bind()
# pprint('[bind] BIND SUCCESS!') # pprint('[bind] BIND SUCCESS!')
print(coordinator_info) # print(coordinator_info)
try: try:
while True: while True:
operation = input() operation = input()
...@@ -95,9 +95,9 @@ if __name__ == '__main__': ...@@ -95,9 +95,9 @@ if __name__ == '__main__':
break break
# todo: add end condition # todo: add end condition
except EOFError: except EOFError:
gprint("[Client] - All commands in .txt file executed. Client Exits..") # gprint("[Client] - All commands in .txt file executed. Client Exits..")
os._exit(0) os._exit(0)
finally: finally:
client_to_coordinator_socket.close() client_to_coordinator_socket.close()
gprint("[Client] - client_to_coordinator_socket CLOSED..") # gprint("[Client] - client_to_coordinator_socket CLOSED..")
# coordinator_to_client_socket.close() # coordinator_to_client_socket.close()
This diff is collapsed.
import random import random
from constants import SERVER_IDENTIFIER, SERVER_ADDRESS, SERVER_PORT, ENCODING_FORMAT, MSG_LENGTH from constants import SERVER_IDENTIFIER, SERVER_ADDRESS, SERVER_PORT, ENCODING_FORMAT, MSG_LENGTH
from utils import gprint, pprint # from utils import gprint, pprint
import os import os
import sys import sys
import socket import socket
...@@ -37,9 +37,9 @@ def connect(coordinator_info: tuple): ...@@ -37,9 +37,9 @@ def connect(coordinator_info: tuple):
coordinator_port_number = coordinator_info[1][SERVER_PORT] coordinator_port_number = coordinator_info[1][SERVER_PORT]
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
address = (coordinator_ip_address, coordinator_port_number) address = (coordinator_ip_address, coordinator_port_number)
pprint(f'[connect] - client connecting to address {address}') # pprint(f'[connect] - client connecting to address {address}')
client.connect(address) client.connect(address)
pprint(f'[connect] - client connecting to address {address} success!') # pprint(f'[connect] - client connecting to address {address} success!')
return client return client
...@@ -48,17 +48,17 @@ def bind(): ...@@ -48,17 +48,17 @@ def bind():
server.bind(ADDR) server.bind(ADDR)
server.listen() server.listen()
conn, addr = server.accept() conn, addr = server.accept()
gprint(f"[Bind] - Bind to {addr} success!") # gprint(f"[Bind] - Bind to {addr} success!")
return conn return conn
def send_operation(operation_str, socket): def send_operation(operation_str, socket):
msg = operation_str.encode(ENCODING_FORMAT) msg = operation_str.encode(ENCODING_FORMAT) # todo: upper case
msg_length = len(msg) msg_length = len(msg)
# send_length = str(msg_length).encode(ENCODING_FORMAT) # send_length = str(msg_length).encode(ENCODING_FORMAT)
msg += b' ' * (MSG_LENGTH - msg_length) msg += b' ' * (MSG_LENGTH - msg_length)
# pprint(f'[send_operation] - {locals()}') # pprint(f'[send_operation] - {locals()}')
pprint(f'[send_operation] - msg.length : {len(msg)}') # pprint(f'[send_operation] - msg.length : {len(msg)}')
socket.sendall(msg) socket.sendall(msg)
...@@ -77,10 +77,10 @@ if __name__ == '__main__': ...@@ -77,10 +77,10 @@ if __name__ == '__main__':
coordinator_info = pick_coordinator(servers) coordinator_info = pick_coordinator(servers)
client_to_coordinator_socket = connect(coordinator_info) client_to_coordinator_socket = connect(coordinator_info)
pprint('[client_to_coordinator_socket] CONNECT SUCCESS!') # pprint('[client_to_coordinator_socket] CONNECT SUCCESS!')
# coordinator_to_client_socket = bind() # coordinator_to_client_socket = bind()
# pprint('[bind] BIND SUCCESS!') # pprint('[bind] BIND SUCCESS!')
print(coordinator_info) # print(coordinator_info)
try: try:
while True: while True:
operation = input() operation = input()
...@@ -95,9 +95,9 @@ if __name__ == '__main__': ...@@ -95,9 +95,9 @@ if __name__ == '__main__':
break break
# todo: add end condition # todo: add end condition
except EOFError: except EOFError:
gprint("[Client] - All commands in .txt file executed. Client Exits..") # gprint("[Client] - All commands in .txt file executed. Client Exits..")
os._exit(0) os._exit(0)
finally: finally:
client_to_coordinator_socket.close() client_to_coordinator_socket.close()
gprint("[Client] - client_to_coordinator_socket CLOSED..") # gprint("[Client] - client_to_coordinator_socket CLOSED..")
# coordinator_to_client_socket.close() # coordinator_to_client_socket.close()
A 127.0.0.1 10001 A sp22-cs425-g68-01.cs.illinois.edu 1234
B 127.0.0.1 10002 B sp22-cs425-g68-02.cs.illinois.edu 1234
C 127.0.0.1 10003 C sp22-cs425-g68-03.cs.illinois.edu 1234
D 127.0.0.1 10004 D sp22-cs425-g68-04.cs.illinois.edu 1234
E 127.0.0.1 10005 E sp22-cs425-g68-05.cs.illinois.edu 1234
\ No newline at end of file
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment