2.4 Write a stream –based echo server and a client sending message to it, and receiving back each message in turn until the client terminates the connection. Hint: Modify the stream-based TCP client and server programs in this chapter or similar programs to transfer multiple messages back and forth. Solution The Transmission Control Protocol (TCP) is a stream-based method of network communication. And one of the main protocol of Internet Protocol suite. TCP provides an interface to network communications that is radically different from the USER datagram Protocol(UDP). The properties of TCP make it highly attractive to network programmers and it simplifies network communication by removing many of the obstacles of UDP, such as ordering of packets and packet loss. TCP focuses instead on establishing a network connection, through which a stream of bytes may be sent and received. It establishes a \"virtual connection\" between two machines, through which stream of data may be sent. TCP uses a lowel-level communications protocol, the internet protocol to establish the connection between machines.This connection provides an interface that allows stream of bytes to be sent and received and to convert the data into IP datagram packets. Simple Echo Server Program: import socket host = \' \' port = 5000 backlog = 1024 s = socket.socket(socket.AF-INET, socket.SOCK-STREAM) s.bind ((host,port)) s.listen(backlog) while 1: client, address = s. accept() data = client.recv(size) if data; client.send(data) client.close() TCP ECHO CLIENT USING STREAMS: import asyncio @asyncio.coroutine def tcp-echo-client(message, loop); reader, writer = yield from asyncio.open-connection(loop = loop) printf(\"send:% message) writer.write(message.encode()) data = yield from reader.read(100) print(\'received: %r\' %data.decode()) print(\'close the socket\') writer.close() message = \'Hello World\' loop = asyncio.get-event-loop() loop.run-until-complete-echo-client(message,loop) loop.close().