Question
Using these two files: --------------------server.py-------------------- import socket last_message = NONE s = socket.socket() print Socket successfully created port = 12345 s.bind(('', port)) print socket binded
Using these two files: --------------------server.py--------------------
import socket
last_message = "NONE"
s = socket.socket()
print "Socket successfully created"
port = 12345
s.bind(('', port))
print "socket binded to %s" %(port)
s.listen(5)
print "socket is listening"
while True:
c, addr = s.accept()
print 'Got connection from', addr
print 'Sending last message'
c.send(last_message)
msg = c.recv(1024)
print 'new message recieved:'
print msg
last_message = msg
c.close() --------------------client.py--------------------
# Import socket module
import socket
# Create a socket object
s = socket.socket()
# Define the port on which you want to connect
port = 12345
msg = raw_input("Message to send: ")
# connect to the server on local computer
s.connect(('127.0.0.1', port))
s.send(msg)
print s.recv(1024)
# close the connection
s.close() Make it so these two files will be able to send messages back and forth to one another in separate terminal sessions. And make a third file, that can *spoof* a message in the conversation. (A third sender acting as one in the two-way conversation).
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