Answered step by step
Verified Expert Solution
Question
1 Approved Answer
CAN YOU HELP ME FINISH PLEASE (THANKYOU IN ADVANCE) Server side Received connection from (IP, PORT): ('127.0.0.1', 53888) Received Data: version: 17 message_type: 1 length:
CAN YOU HELP ME FINISH PLEASE (THANKYOU IN ADVANCE)
Server side
Received connection from (IP, PORT): ('127.0.0.1', 53888) Received Data: version: 17 message_type: 1 length: 1280 VERSION ACCEPTED Received Data: version: 17 message_type: 2 length: 1792 VERSION ACCEPTED EXECUTING SUPPORTED COMMAND: LIGHTON Returning SUCCESS Received connection from (IP, PORT): ('127.0.0.1', 53890) Received Data: version: 17 message_type: 1 length: 1280 VERSION ACCEPTED Received Data: version: 17 message_type: 2 length: 1792 VERSION ACCEPTED EXECUTING SUPPORTED COMMAND: LIGHTON Returning SUCCESS
Client Side
Run 1
Received Data: version: 17 type: 1 length: 1280 VERSION ACCEPTED Received Message Hello Sending command Received Data: version: 17 type: 2 length: 1792 VERSION ACCEPTED Received Message SUCCESS Command Successful Closing socket
Run 2
Sending HELLO Packet Received Data: version: 17 type: 1 length: 1280 VERSION ACCEPTED Received Message Hello Sending command Received Data: version: 17 type: 2 length: 1792 VERSION ACCEPTED Received Message SUCCESS Command Successful Closing socket
CODE I HAVE ALREADY DONE
SERVER.py
import socket import threading def handle_client(conn, addr): print("Handling connection from {}".format(addr)) while conn: conn.recv(1024) #decoded_message = message_header.decode(ENCODING) print("Received message from client: {}".format(decoded_message)) break if __name__ == '__main__': print("Creating a socket") server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) PORT = 8001 IP_ADDR = socket.gethostbyname(socket.gethostname()) SERVER_ADDR = (IP_ADDR, PORT) print("Binding to {}".format(SERVER_ADDR)) while True: connection, address = server_socket.accept() print("Received a connection from (IP, PORT):{}".format(SERVER_ADDR)) thread = threading.Thread(target=handle_client, args=(connection, address)) thread.start() connection.close() print('client disconnected') CLIENT.py
import socket REMOTE_ADDR = socket.gethostbyname(socket.gethostname()) REMOTE_PORT = 8001 SERVER_ADDR = (REMOTE_ADDR, REMOTE_PORT) ENCODING = 'utf-8' message = "HELLO" encoded_message = message.encode(ENCODING) length_msg = str(len(encoded_message)).encode(ENCODING) client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client.connect(SERVER_ADDR) print(length_msg) client.send(length_msg) print(encoded_message) client.send(encoded_message)
can you help me finish thankyou
1. Write a server that listens for incoming connections on the specified port. 2. Server must parse two command line arguments port and log locations. 3. The server must not exit after receiving a single packet. 4. Once a client connects it logs a message in the following format "Received connection fromStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started