Answered step by step
Verified Expert Solution
Link Copied!

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)

image text in transcribedimage text in transcribed

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 from 5. Once it receives a HELLO message from the client, it logs the connection and sends a HELLO back to the client. 6. You can assume the packet format is the following: version (4 bytes) |Message type (4 bytes) Message Length (4 bytes) | 1 1 Message (Max 8 Bytes) 7. It receives the packet header first, followed by the message. Hint: You need two RECV calls. 8. Check if Version == 17. If not, log an error message VERSION MISMATCH and continue to listen. Do not exit. 9. If Version == 17, check the message type. If message Type is 1- the corresponding command is LIGHTON. If message type is 2 - the corresponding command is LIGHTOFF . No other command is supported. 10. If the server sees a supported command, log "EXECUTING SUPPORTED COMMAND: COMMANDNAME, else log -D -1 LOGFILE The client takes three arguments: 1. Server IP - The IP address of the server. 2. PORT - The port the server listens on. 3. Log file location - Where you will keep a record of packets you received. For example: $ lightclient -5 192.168.2.1 -p 6543 -1 LOGFILE 4. The client must parse three command line arguments, server, port, and logfile. 5. The client should connect to the server on the specified port. 6. Constructs and sends a hello packet to the server. 1 Message Length (4 bytes) | version (4 bytes) |Message type (4 bytes) 1 1 1 Message (HELLO) 7. Receive reply from Server - if version is 17, log "VERSION ACCEPTED", else log - "VERSION MISMATCH" 8. If version is accepted, send a command packet. 1 version (4 bytes) |Message type (4 bytes) Message Length (4 bytes) | 1 1 COMMAND (LIGHTON/LIGHTOFF) 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 from 5. Once it receives a HELLO message from the client, it logs the connection and sends a HELLO back to the client. 6. You can assume the packet format is the following: version (4 bytes) |Message type (4 bytes) Message Length (4 bytes) | 1 1 Message (Max 8 Bytes) 7. It receives the packet header first, followed by the message. Hint: You need two RECV calls. 8. Check if Version == 17. If not, log an error message VERSION MISMATCH and continue to listen. Do not exit. 9. If Version == 17, check the message type. If message Type is 1- the corresponding command is LIGHTON. If message type is 2 - the corresponding command is LIGHTOFF . No other command is supported. 10. If the server sees a supported command, log "EXECUTING SUPPORTED COMMAND: COMMANDNAME, else log -D -1 LOGFILE The client takes three arguments: 1. Server IP - The IP address of the server. 2. PORT - The port the server listens on. 3. Log file location - Where you will keep a record of packets you received. For example: $ lightclient -5 192.168.2.1 -p 6543 -1 LOGFILE 4. The client must parse three command line arguments, server, port, and logfile. 5. The client should connect to the server on the specified port. 6. Constructs and sends a hello packet to the server. 1 Message Length (4 bytes) | version (4 bytes) |Message type (4 bytes) 1 1 1 Message (HELLO) 7. Receive reply from Server - if version is 17, log "VERSION ACCEPTED", else log - "VERSION MISMATCH" 8. If version is accepted, send a command packet. 1 version (4 bytes) |Message type (4 bytes) Message Length (4 bytes) | 1 1 COMMAND (LIGHTON/LIGHTOFF)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Shamkant B. Navathe

7th Edition Global Edition

1292097612, 978-1292097619

More Books

Students also viewed these Databases questions