Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write code in PYTHON.TWO FILES SERVER.PY and CLIENT.PY Keeping the specifications in mind below Modify the client.py and server.py provided and Use a 2 dimensional
Write code in PYTHON.TWO FILES SERVER.PY and CLIENT.PY
Keeping the specifications in mind below
Modify the client.py and server.py provided and
Use a 2 dimensional parity checker.
A. Simple server
#!/usr/bin/python
import socket # Import socket module
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0) # Create a socket object
host = socket.gethostbyname(socket.gethostname()) # Get local machine name
port = 12345 # Reserve a port for your service.
s.bind((host, port)) # Bind to the port
print 'host ip', host
s.listen(5) # Now wait for client connection.
while True:
c, addr = s.accept() # Establish connection with client.
print 'Got connection from', addr
c.send('Thank you for connecting')
c.close() # Close the connection
B. Simple client
#!/usr/bin/python # This is client.py file
import socket # Import socket module
s = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name/for this example
ports = 12345 #server port
portc = 32451 #client's own port for incoming connections (if any)
s.bind((host, portc))
s.connect((host, ports))
print s.recv(1024)
s.close # Close the socket when done
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