7 # action can be reflect or drop
10 def handle_connection (connection, client_address):
11 print("Received connection from {}".format(repr(client_address)))
14 data = connection.recv(4096)
17 if (action != "drop"):
18 connection.sendall(data)
22 def run_server(ip, port):
23 print("Starting server {}:{}".format(repr(ip), repr(port)))
24 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
25 server_address = (ip, int(port))
26 sock.bind(server_address)
30 connection, client_address = sock.accept()
31 handle_connection (connection, client_address)
35 for i in range (0, pow(2, 16)):
39 def run_client(ip, port):
40 print("Starting client {}:{}".format(repr(ip), repr(port)))
41 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
42 server_address = ("6.0.1.1", 1234)
43 sock.connect(server_address)
51 def run(mode, ip, port):
52 if (mode == "server"):
54 elif (mode == "client"):
57 raise Exception("Unknown mode. Only client and server supported")
59 if __name__ == "__main__":
60 if (len(sys.argv)) < 4:
61 raise Exception("Usage: ./dummy_app <mode> <ip> <port> [<action>]")
62 if (len(sys.argv) == 5):
65 run (sys.argv[1], sys.argv[2], sys.argv[3])