SlideShare a Scribd company logo
1 of 2
Download to read offline
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()

More Related Content

Similar to 2.4 Write a stream –based echo server and a client sending message t.pdf

Transport Layer [Autosaved]
Transport Layer [Autosaved]Transport Layer [Autosaved]
Transport Layer [Autosaved]Ram Dutt Shukla
 
Socket Programming by Rajkumar Buyya
Socket Programming by Rajkumar BuyyaSocket Programming by Rajkumar Buyya
Socket Programming by Rajkumar BuyyaiDhawalVaja
 
Identify and describe each phase (numbered) in the TCP trace- Make sur.docx
Identify and describe each phase (numbered) in the TCP trace- Make sur.docxIdentify and describe each phase (numbered) in the TCP trace- Make sur.docx
Identify and describe each phase (numbered) in the TCP trace- Make sur.docxmckerliejonelle
 
Identify and describe each phase (numbered) in the TCP trace. Make su.docx
 Identify and describe each phase (numbered) in the TCP trace. Make su.docx Identify and describe each phase (numbered) in the TCP trace. Make su.docx
Identify and describe each phase (numbered) in the TCP trace. Make su.docxAbhinav816839
 
Internet of things protocols for resource constrained applications
Internet of things protocols for resource constrained applications Internet of things protocols for resource constrained applications
Internet of things protocols for resource constrained applications Pokala Sai
 
Computer Communication Networks- TRANSPORT LAYER PROTOCOLS
Computer Communication Networks- TRANSPORT LAYER PROTOCOLSComputer Communication Networks- TRANSPORT LAYER PROTOCOLS
Computer Communication Networks- TRANSPORT LAYER PROTOCOLSKrishna Nanda
 
CSS (KNC-301) 2. TCP IP By Vivek Tripathi.pptx
CSS (KNC-301)  2. TCP IP By Vivek Tripathi.pptxCSS (KNC-301)  2. TCP IP By Vivek Tripathi.pptx
CSS (KNC-301) 2. TCP IP By Vivek Tripathi.pptxVivekTripathi684438
 
Java Network Programming.pptx
Java Network Programming.pptxJava Network Programming.pptx
Java Network Programming.pptxRoshniSundrani
 
Ajp notes-chapter-04
Ajp notes-chapter-04Ajp notes-chapter-04
Ajp notes-chapter-04Ankit Dubey
 
Chapter Five - Transport Layer.pptx
Chapter Five - Transport Layer.pptxChapter Five - Transport Layer.pptx
Chapter Five - Transport Layer.pptxGirT2
 
Internet of Things Unit - 01 Part 3A.pptx
Internet of Things Unit - 01 Part 3A.pptxInternet of Things Unit - 01 Part 3A.pptx
Internet of Things Unit - 01 Part 3A.pptxSunilNirmal9
 
HNS L III UC2 Installing and Managing Network Protocols .pdf
HNS L III UC2 Installing and Managing Network Protocols .pdfHNS L III UC2 Installing and Managing Network Protocols .pdf
HNS L III UC2 Installing and Managing Network Protocols .pdfAbenetAsmellash
 

Similar to 2.4 Write a stream –based echo server and a client sending message t.pdf (20)

TCP Vs UDP
TCP Vs UDP TCP Vs UDP
TCP Vs UDP
 
Week10 transport
Week10 transportWeek10 transport
Week10 transport
 
Transport Layer
Transport LayerTransport Layer
Transport Layer
 
Transport Layer [Autosaved]
Transport Layer [Autosaved]Transport Layer [Autosaved]
Transport Layer [Autosaved]
 
Socket Programming by Rajkumar Buyya
Socket Programming by Rajkumar BuyyaSocket Programming by Rajkumar Buyya
Socket Programming by Rajkumar Buyya
 
Networking in python by Rj
Networking in python by RjNetworking in python by Rj
Networking in python by Rj
 
Identify and describe each phase (numbered) in the TCP trace- Make sur.docx
Identify and describe each phase (numbered) in the TCP trace- Make sur.docxIdentify and describe each phase (numbered) in the TCP trace- Make sur.docx
Identify and describe each phase (numbered) in the TCP trace- Make sur.docx
 
Identify and describe each phase (numbered) in the TCP trace. Make su.docx
 Identify and describe each phase (numbered) in the TCP trace. Make su.docx Identify and describe each phase (numbered) in the TCP trace. Make su.docx
Identify and describe each phase (numbered) in the TCP trace. Make su.docx
 
Transport layer
Transport layer Transport layer
Transport layer
 
Internet of things protocols for resource constrained applications
Internet of things protocols for resource constrained applications Internet of things protocols for resource constrained applications
Internet of things protocols for resource constrained applications
 
Computer Communication Networks- TRANSPORT LAYER PROTOCOLS
Computer Communication Networks- TRANSPORT LAYER PROTOCOLSComputer Communication Networks- TRANSPORT LAYER PROTOCOLS
Computer Communication Networks- TRANSPORT LAYER PROTOCOLS
 
計概
計概計概
計概
 
Transport layer
Transport layerTransport layer
Transport layer
 
TCP Section5
TCP Section5TCP Section5
TCP Section5
 
CSS (KNC-301) 2. TCP IP By Vivek Tripathi.pptx
CSS (KNC-301)  2. TCP IP By Vivek Tripathi.pptxCSS (KNC-301)  2. TCP IP By Vivek Tripathi.pptx
CSS (KNC-301) 2. TCP IP By Vivek Tripathi.pptx
 
Java Network Programming.pptx
Java Network Programming.pptxJava Network Programming.pptx
Java Network Programming.pptx
 
Ajp notes-chapter-04
Ajp notes-chapter-04Ajp notes-chapter-04
Ajp notes-chapter-04
 
Chapter Five - Transport Layer.pptx
Chapter Five - Transport Layer.pptxChapter Five - Transport Layer.pptx
Chapter Five - Transport Layer.pptx
 
Internet of Things Unit - 01 Part 3A.pptx
Internet of Things Unit - 01 Part 3A.pptxInternet of Things Unit - 01 Part 3A.pptx
Internet of Things Unit - 01 Part 3A.pptx
 
HNS L III UC2 Installing and Managing Network Protocols .pdf
HNS L III UC2 Installing and Managing Network Protocols .pdfHNS L III UC2 Installing and Managing Network Protocols .pdf
HNS L III UC2 Installing and Managing Network Protocols .pdf
 

More from excellentmobiles

How is the spleen like a lymph node How is it unlike a lymph node .pdf
How is the spleen like a lymph node How is it unlike a lymph node .pdfHow is the spleen like a lymph node How is it unlike a lymph node .pdf
How is the spleen like a lymph node How is it unlike a lymph node .pdfexcellentmobiles
 
Give two advantages and two disadvantages of placing IO function in.pdf
Give two advantages and two disadvantages of placing IO function in.pdfGive two advantages and two disadvantages of placing IO function in.pdf
Give two advantages and two disadvantages of placing IO function in.pdfexcellentmobiles
 
Frances drop in output per capita relative to U.S. output per capi.pdf
Frances drop in output per capita relative to U.S. output per capi.pdfFrances drop in output per capita relative to U.S. output per capi.pdf
Frances drop in output per capita relative to U.S. output per capi.pdfexcellentmobiles
 
Describe the effect of cyanide ion, CN^-, on oxidative phosphorylatio.pdf
Describe the effect of cyanide ion, CN^-, on oxidative phosphorylatio.pdfDescribe the effect of cyanide ion, CN^-, on oxidative phosphorylatio.pdf
Describe the effect of cyanide ion, CN^-, on oxidative phosphorylatio.pdfexcellentmobiles
 
Describe synchronization techniques used by programmers who develop .pdf
Describe synchronization techniques used by programmers who develop .pdfDescribe synchronization techniques used by programmers who develop .pdf
Describe synchronization techniques used by programmers who develop .pdfexcellentmobiles
 
Barney had a bag of cookies. He ate 35 in the first 10 minutes. He a.pdf
Barney had a bag of cookies. He ate 35 in the first 10 minutes. He a.pdfBarney had a bag of cookies. He ate 35 in the first 10 minutes. He a.pdf
Barney had a bag of cookies. He ate 35 in the first 10 minutes. He a.pdfexcellentmobiles
 
11. In the United States, financial statement audits of non-public co.pdf
11. In the United States, financial statement audits of non-public co.pdf11. In the United States, financial statement audits of non-public co.pdf
11. In the United States, financial statement audits of non-public co.pdfexcellentmobiles
 
When you make the following dihybrid testcross MmPp x mmpp, what is .pdf
When you make the following dihybrid testcross MmPp x mmpp, what is .pdfWhen you make the following dihybrid testcross MmPp x mmpp, what is .pdf
When you make the following dihybrid testcross MmPp x mmpp, what is .pdfexcellentmobiles
 
Why do you think nursing core competencies were selectedWhy do .pdf
Why do you think nursing core competencies were selectedWhy do .pdfWhy do you think nursing core competencies were selectedWhy do .pdf
Why do you think nursing core competencies were selectedWhy do .pdfexcellentmobiles
 
Which of the following is true of water It is a phospholipid It is.pdf
Which of the following is true of water  It is a phospholipid  It is.pdfWhich of the following is true of water  It is a phospholipid  It is.pdf
Which of the following is true of water It is a phospholipid It is.pdfexcellentmobiles
 
Which of the following are considered to be alive and whyProteins.pdf
Which of the following are considered to be alive and whyProteins.pdfWhich of the following are considered to be alive and whyProteins.pdf
Which of the following are considered to be alive and whyProteins.pdfexcellentmobiles
 
Which of the following are actually vector spaces over the real numbe.pdf
Which of the following are actually vector spaces over the real numbe.pdfWhich of the following are actually vector spaces over the real numbe.pdf
Which of the following are actually vector spaces over the real numbe.pdfexcellentmobiles
 
What is the change of entropy of water (Lf = 0.333 MJkg, Lv = 2.26 .pdf
What is the change of entropy of water (Lf = 0.333 MJkg, Lv = 2.26 .pdfWhat is the change of entropy of water (Lf = 0.333 MJkg, Lv = 2.26 .pdf
What is the change of entropy of water (Lf = 0.333 MJkg, Lv = 2.26 .pdfexcellentmobiles
 
What are the epidemiological characteristics of infection with avian.pdf
What are the epidemiological characteristics of infection with avian.pdfWhat are the epidemiological characteristics of infection with avian.pdf
What are the epidemiological characteristics of infection with avian.pdfexcellentmobiles
 
What benefits if any, are inherent with interactive communication fo.pdf
What benefits if any, are inherent with interactive communication fo.pdfWhat benefits if any, are inherent with interactive communication fo.pdf
What benefits if any, are inherent with interactive communication fo.pdfexcellentmobiles
 
What are the features of linear and charter What are the featur.pdf
What are the features of linear and charter What are the featur.pdfWhat are the features of linear and charter What are the featur.pdf
What are the features of linear and charter What are the featur.pdfexcellentmobiles
 
W hy is D the answer Why does it not indicate the same relations.pdf
W hy is D the answer Why does it not indicate the same relations.pdfW hy is D the answer Why does it not indicate the same relations.pdf
W hy is D the answer Why does it not indicate the same relations.pdfexcellentmobiles
 
what are handles, WS private, WS shared and Working set used for in .pdf
what are handles, WS private, WS shared and Working set used for in .pdfwhat are handles, WS private, WS shared and Working set used for in .pdf
what are handles, WS private, WS shared and Working set used for in .pdfexcellentmobiles
 
USA Today conducted a survey asking readers, “What is the most hilar.pdf
USA Today conducted a survey asking readers, “What is the most hilar.pdfUSA Today conducted a survey asking readers, “What is the most hilar.pdf
USA Today conducted a survey asking readers, “What is the most hilar.pdfexcellentmobiles
 
The distance between two successive minima of a transverse wave i.pdf
The distance between two successive minima of a transverse wave i.pdfThe distance between two successive minima of a transverse wave i.pdf
The distance between two successive minima of a transverse wave i.pdfexcellentmobiles
 

More from excellentmobiles (20)

How is the spleen like a lymph node How is it unlike a lymph node .pdf
How is the spleen like a lymph node How is it unlike a lymph node .pdfHow is the spleen like a lymph node How is it unlike a lymph node .pdf
How is the spleen like a lymph node How is it unlike a lymph node .pdf
 
Give two advantages and two disadvantages of placing IO function in.pdf
Give two advantages and two disadvantages of placing IO function in.pdfGive two advantages and two disadvantages of placing IO function in.pdf
Give two advantages and two disadvantages of placing IO function in.pdf
 
Frances drop in output per capita relative to U.S. output per capi.pdf
Frances drop in output per capita relative to U.S. output per capi.pdfFrances drop in output per capita relative to U.S. output per capi.pdf
Frances drop in output per capita relative to U.S. output per capi.pdf
 
Describe the effect of cyanide ion, CN^-, on oxidative phosphorylatio.pdf
Describe the effect of cyanide ion, CN^-, on oxidative phosphorylatio.pdfDescribe the effect of cyanide ion, CN^-, on oxidative phosphorylatio.pdf
Describe the effect of cyanide ion, CN^-, on oxidative phosphorylatio.pdf
 
Describe synchronization techniques used by programmers who develop .pdf
Describe synchronization techniques used by programmers who develop .pdfDescribe synchronization techniques used by programmers who develop .pdf
Describe synchronization techniques used by programmers who develop .pdf
 
Barney had a bag of cookies. He ate 35 in the first 10 minutes. He a.pdf
Barney had a bag of cookies. He ate 35 in the first 10 minutes. He a.pdfBarney had a bag of cookies. He ate 35 in the first 10 minutes. He a.pdf
Barney had a bag of cookies. He ate 35 in the first 10 minutes. He a.pdf
 
11. In the United States, financial statement audits of non-public co.pdf
11. In the United States, financial statement audits of non-public co.pdf11. In the United States, financial statement audits of non-public co.pdf
11. In the United States, financial statement audits of non-public co.pdf
 
When you make the following dihybrid testcross MmPp x mmpp, what is .pdf
When you make the following dihybrid testcross MmPp x mmpp, what is .pdfWhen you make the following dihybrid testcross MmPp x mmpp, what is .pdf
When you make the following dihybrid testcross MmPp x mmpp, what is .pdf
 
Why do you think nursing core competencies were selectedWhy do .pdf
Why do you think nursing core competencies were selectedWhy do .pdfWhy do you think nursing core competencies were selectedWhy do .pdf
Why do you think nursing core competencies were selectedWhy do .pdf
 
Which of the following is true of water It is a phospholipid It is.pdf
Which of the following is true of water  It is a phospholipid  It is.pdfWhich of the following is true of water  It is a phospholipid  It is.pdf
Which of the following is true of water It is a phospholipid It is.pdf
 
Which of the following are considered to be alive and whyProteins.pdf
Which of the following are considered to be alive and whyProteins.pdfWhich of the following are considered to be alive and whyProteins.pdf
Which of the following are considered to be alive and whyProteins.pdf
 
Which of the following are actually vector spaces over the real numbe.pdf
Which of the following are actually vector spaces over the real numbe.pdfWhich of the following are actually vector spaces over the real numbe.pdf
Which of the following are actually vector spaces over the real numbe.pdf
 
What is the change of entropy of water (Lf = 0.333 MJkg, Lv = 2.26 .pdf
What is the change of entropy of water (Lf = 0.333 MJkg, Lv = 2.26 .pdfWhat is the change of entropy of water (Lf = 0.333 MJkg, Lv = 2.26 .pdf
What is the change of entropy of water (Lf = 0.333 MJkg, Lv = 2.26 .pdf
 
What are the epidemiological characteristics of infection with avian.pdf
What are the epidemiological characteristics of infection with avian.pdfWhat are the epidemiological characteristics of infection with avian.pdf
What are the epidemiological characteristics of infection with avian.pdf
 
What benefits if any, are inherent with interactive communication fo.pdf
What benefits if any, are inherent with interactive communication fo.pdfWhat benefits if any, are inherent with interactive communication fo.pdf
What benefits if any, are inherent with interactive communication fo.pdf
 
What are the features of linear and charter What are the featur.pdf
What are the features of linear and charter What are the featur.pdfWhat are the features of linear and charter What are the featur.pdf
What are the features of linear and charter What are the featur.pdf
 
W hy is D the answer Why does it not indicate the same relations.pdf
W hy is D the answer Why does it not indicate the same relations.pdfW hy is D the answer Why does it not indicate the same relations.pdf
W hy is D the answer Why does it not indicate the same relations.pdf
 
what are handles, WS private, WS shared and Working set used for in .pdf
what are handles, WS private, WS shared and Working set used for in .pdfwhat are handles, WS private, WS shared and Working set used for in .pdf
what are handles, WS private, WS shared and Working set used for in .pdf
 
USA Today conducted a survey asking readers, “What is the most hilar.pdf
USA Today conducted a survey asking readers, “What is the most hilar.pdfUSA Today conducted a survey asking readers, “What is the most hilar.pdf
USA Today conducted a survey asking readers, “What is the most hilar.pdf
 
The distance between two successive minima of a transverse wave i.pdf
The distance between two successive minima of a transverse wave i.pdfThe distance between two successive minima of a transverse wave i.pdf
The distance between two successive minima of a transverse wave i.pdf
 

Recently uploaded

Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 

Recently uploaded (20)

Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 

2.4 Write a stream –based echo server and a client sending message t.pdf

  • 1. 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()
  • 2. 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()