Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In python, how can I pull the data sent by the client out in the server and use it in functions. Here is my Client

In python, how can I pull the data sent by the client out in the server and use it in functions. Here is my Client py and my server py.

client - Which I get no errors

import socket import sys # function: mbr # purpose: open the binary file # inputs: binary file identified below # returns: creates a bytearray to store the chunk of data pulled from the file def mbr(file_name): try: chunk = bytearray() the_file = open(file_name, 'rb') chunk = the_file.read() finally: return chunk # function: search # purpose: allows the user to search for information against the mbr file # inputs: the mbr file and user search parameters # returns: value that meets the search parameters def search(a, b): try: search = a[b] finally: return search # Defines the file that will be imported and follow the above defined mbr function binary = mbr("block.dd") # Create a TCP/IP socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Connect the socket to the port where the server is listening server_address = ("127.0.0.1", 3333) print('connecting to {} port {}'.format(*server_address)) sock.connect(server_address) try: # Send data message = binary print("Sent MBR chunk".format(message)) sock.sendall(message) finally: print('closing socket') sock.close()

Server py - Which I get the following error message.

Traceback (most recent call last): File "/Users/lorianne/PycharmProjects/Week 4/Wk 4 - Server.py", line 29, in connection.sendall (data) BrokenPipeError: [Errno 32] Broken pipe

import struct import socket import sys # Create a TCP/IP socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Bind the socket to the port server_address = ("127.0.0.1", 3333) print('starting up on {} port {}'.format(*server_address)) sock.bind(server_address) # Listen for incoming connections sock.listen(1) while True: # Wait for a connection print('waiting for a connection') connection, client_address = sock.accept() try: print('connection from', client_address) # Receive the data in small chunks and retransmit it while True: data = connection.recv(16) print("Received MBR chunk".format(data)) if data: print('sending data back to the client') connection.sendall (data) else: print('no data from', client_address) break finally: # Clean up the connection connection.close() # function: search # purpose: allows the user to search for information against the mbr file # inputs: the mbr file and user search parameters # returns: value that meets the search parameters def search(a, b): try: search = a[b] finally: return search # Input the variables that were provided in the above assignment description status = 0x1BE partition = 0x1BE + 8 # Defines the file that will be imported and follow the above defined mbr function binary = mbr("block.dd") # A search that requests the status of the 1 byte located at 1BE print("Status of 1 byte located at 1BE is: " + str(search(binary, status))) # A search that request the partition type of the 1 byte located at 1BE+4 print("The partition type of 1 byte located at 1BE+4 is: " + str(search(binary, partition))) # Creates the partition address variable address = struct.unpack('                        

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

Advances In Database Technology Edbt 88 International Conference On Extending Database Technology Venice Italy March 14 18 1988 Proceedings Lncs 303

Authors: Joachim W. Schmidt ,Stefano Ceri ,Michele Missikoff

1988th Edition

3540190740, 978-3540190745

More Books

Students also viewed these Databases questions

Question

7. Understand the challenges of multilingualism.

Answered: 1 week ago