1. Engineering
  2. Computer Science
  3. please change some of these codes so the output can...

Question: please change some of these codes so the output can...

Question details

please change some of these codes so the output can look like this:

$ python TCPClient.py

socket created

connected

sent

received data: HELLO.

==================================

(TCPServer.py)

import socket

TCP_IP = '127.0.0.2'
TCP_PORT = 20000
BUFFER_SIZE = 1024

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((TCP_IP, TCP_PORT))
s.listen(1)

while True:
    conn, addr = s.accept()
    print ('Connection address:', addr)
    data = conn.recv(BUFFER_SIZE)
    print( "received data:" , data)
    conn.secd(data)
    conn.close()

----------------------------------------------------------------

(TCPClient.py)

import socket


TCP_IP = '127.0.0.2'
TCP_PORT = 20000
BUFFER_SIZE = 1024
MESSAGE = "HELLO"

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print ("socket created")
s.connect((TCP_IP, TCP_PORT))
print ("connected")
s.send(MESSAGE)
print ("sent")
data = s.recv(BUFFER_SIZE)
s.close()

print ("received data:" ,data)
Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution