Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Echo Server Problem. Contents  Basic Networking Concepts  The Echo Server Problem.

Similar presentations


Presentation on theme: "The Echo Server Problem. Contents  Basic Networking Concepts  The Echo Server Problem."— Presentation transcript:

1 The Echo Server Problem

2 Contents  Basic Networking Concepts  The Echo Server Problem

3 I. Basic Networking Concepts  Connection-Oriented Service  Port  Socket

4 1. Connection-Oriented Server User establishes a connection and maintains that connection This type of data transport protocol is a three- phase operation  Creating the connection This process is also known as a "handshake" between the devices.  Data transmission The sending computer waits for an acknowledgement message between each part of the transmission. If an acknowledgement is not received, that portion of the transmission is resent until it has been received without error. Breaking the connection

5 2. Port A port is not a physical device, it is just a number that identifies a specific program on the server  Port numbers from 0 to 1023 are reserved for well-known services. Don’t use them for your own server programs!  If you’re writing services (server programs) to run on a company network, you should check with the sys-admins to find out which ports are already taken

6 3. Socket A socket is an abstraction for the network software that enables communication out of and into this program  It represents a network connection between two machines  It contains two streams, one is for reading data coming in, and the other is for writing data out

7 II. The Echo Server Problem Develop a simple server that listens to port 8189 and echoes back all client's input

8 Solution  Main Class to Start the Echo Server  Developing EchoServer Class to Serve One Client at a Time  Improving EchoServer to Serve Multiple Clients at the Same Time

9 1. Main Class to Start the Echo Server

10 2. Developing EchoServer Class to Serve One Client at a Time 2.1. Getting Ready to Receive Incoming Connections 2.2. Waiting Indefinitely for a Connection to Come In 2.3. Serving the Client

11 2.1. Getting Ready to Receive Incoming Connections

12 2.2. Waiting Indefinitely for a Connection to Come In

13 2.3. Serving the Client 2.3.1. The try-finally Template 2.3.2. Checking Whether the Client has Sent a Message 2.3.3. Echoing the Message to the Client 2.3.4. Returning If the Client Stops Sending

14 2.3.1. The try-finally Template

15 2.3.2. Checking Whether the Client has Sent a Message

16 2.3.3. Echoing the Message to the Client

17 2.3.4. Returning If the Client Stops Sending

18 3. Improving EchoServer to Serve Multiple Clients at the Same Time At this moment, the program can serve only one client at a time. Furthermore, after serving that client, the service is closed down 3.1. Making the EchoServer Run Forever 3.2. Serving a Client in a Separate Thread

19 3.1. Making the EchoServer Run Forever

20 3.2. Serving a Client in a Separate Thread

21 The Client Develop a simple client that connects to port 8189 of the server, sends and receive data back from the server.

22 Solution  Main Class to Start the Echo Client  Developing EchoClient Class to Send and Receive from the Server

23 1. Main Class to Start the Echo Client

24 2. Developing EchoClient Class 2.1. Constructing a Socket to Connect to the Echo Server 2.2. Getting Input and Output Streams of the Socket 2.3. Getting Data from the Console, Sending and Retrieving from the Socket.

25 2.1. Constructing a Socket to Connect to the Echo Server

26 2.2. Getting Input and Output Streams of the Socket

27 2.3. Getting Data from the Console, Sending and Retrieving from the Socket

28 References  Core Java, Volume II – Advanced Features, Eighth Edition, Chapter 3. Cay S. Horstmann and Gary Cornell. Prentice Hall, 2008  Building a Java chat server. Greg Travis. ibm.com/developerWorks


Download ppt "The Echo Server Problem. Contents  Basic Networking Concepts  The Echo Server Problem."

Similar presentations


Ads by Google