def goAhead(self, name): self.login.destroy() self.layout(name) nick = name client.send(encode(10, nick)) # the thread to receive messages rcv = threading.Thread(target=self.receive) rcv.start()
def start_tcp_client(): with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as TCPClientSocket: TCPClientSocket.connect((ip, tcp_port)) while True: print(f"TCP: Sending packets with message width of {s} bytes") success = 0 for i in range(n): message = str(time.time()) * 100 message = message[::-1] message = message[:s] TCPClientSocket.sendall(encode(20, body=message)) data = TCPClientSocket.recv(1024) if data: success += 1 success_percentage = success / n * 100 tcp_x_axis.append(time.time() - start_time) tcp_y_axis.append(success_percentage)
def client_server_loop(message): # A function that performs a message round trip (client side) # Client --------------- Server # 1) send(msg) --------------> recv(msg) # 2) recv(msg) <-------------- send(msg) UDPClientSocket.sendto(encode(20, body=message), (ip, udp_port)) try: msgFromServer = UDPClientSocket.recvfrom(buffer_size) if verify(msgFromServer[0]): return 1 else: print("UDP: packet altered") time.sleep(0.15) except socket.timeout: print("UDP: packet dropped") return 0 #will be returned if packet is dropped or altered
def start_udp_client(): global UDPClientSocket UDPClientSocket = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM) UDPClientSocket.settimeout(0.75) while True: UDPClientSocket.sendto(encode(10, "udptest"), (ip, udp_port)) print(f"UDP: Sending packets with message width of {s} bytes") success = 0 for i in range(n): message = str(time.time()) * 100 message = message[::-1] message = message[:s] success += client_server_loop(message) success_percentage = success / n * 100 udp_x_axis.append(time.time() - start_time) udp_y_axis.append(success_percentage)
def sendMessage(self): self.textCons.config(state=DISABLED) while True: message = (f"{self.name}: {self.msg}") client.send(encode(20, nick, body=message)) break