Question
CAN I PLEASE GET HELP WITH THIS? I AM WRITING CODE FOR A PYTHON CLIENT. PLEASE HELP!!! MY CODE SO FAR ********LIGHTCLIENT.PY****** import socket import
CAN I PLEASE GET HELP WITH THIS? I AM WRITING CODE FOR A PYTHON CLIENT. PLEASE HELP!!!
MY CODE SO FAR
********LIGHTCLIENT.PY******
import socket import argparse import struct import binascii
#------------------------------------------------------------------------------- #Arguments parser = argparse.ArgumentParser(description='Client Options') parser.add_argument('-p', '--port', type=int, metavar='', help='Port to be used to send message') parser.add_argument('-s', '--server', type=str, metavar='', help='IP Address of server')
args = parser.parse_args()
#------------------------------------------------------------------------------- #Socket information #-------------------------------------------------------------------------------
hostName = socket.gethostname() REMOTE_ADDR = args.server REMOTE_PORT = args.port SERVER_ADDR = (REMOTE_ADDR, REMOTE_PORT) ENCODING = 'utf-8'
#------------------------------------------------------------------------------- #Creating Struct Packets #-------------------------------------------------------------------------------
values = (17, 1, 1280, 'Hello'.encode('utf-8')) s = struct.Struct('I I I 5s') packed = s.pack(*values)
values2 = (17, 2, 1792, 'Hello'.encode('utf-8')) s2 = struct.Struct('I I I 5s') packed2 = s2.pack(*values2)
#------------------------------------------------------------------------------- #Establishing connections and sending packets and printing results #------------------------------------------------------------------------------- global count count = 0
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client.connect(SERVER_ADDR)
#First Packet sent client.send(packed) print("Sending HELLO Packet")
from_server = client.recv(64).decode('utf-8') print(from_server) from_server = client.recv(64).decode('utf-8') print(from_server) if from_server == 'VERSION ACCEPTED': print("Received Message Hello") print("Sending Command") count = count + 1 client.close()
client2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client2.connect(SERVER_ADDR)
#Second Packet sent client2.send(packed2)
from_server = client2.recv(64).decode('utf-8') print(from_server) from_server = client2.recv(64).decode('utf-8') print(from_server)
if from_server == 'VERSION ACCEPTED': count = count + 1
if count == 2: print("Received Message SUCCESS") print("Command Successful")
client2.close() print("Closing Socket")
$ lightclient -5
Step 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