Generic Connection Framework Connection Input Connection Output Connection

  • Slides: 27
Download presentation
Generic Connection Framework Connection Input. Connection Output. Connection Stream. Connection File. Connection Socket. Connection

Generic Connection Framework Connection Input. Connection Output. Connection Stream. Connection File. Connection Socket. Connection HTTPConnection

Generic Connection Framework Connection Input. Connection void close() Output. Connection Stream. Connection File. Connection

Generic Connection Framework Connection Input. Connection void close() Output. Connection Stream. Connection File. Connection Socket. Connection HTTPConnection

Generic Connection Framework Connection DIS open. Data. Input. Stream() DIS open. Input. Stream() Input.

Generic Connection Framework Connection DIS open. Data. Input. Stream() DIS open. Input. Stream() Input. Connection void close() DOS open. Data. Output. Stream() DOS open. Output. Stream() Output. Connection Stream. Connection File. Connection Socket. Connection HTTPConnection

Generic Connection Framework Connection DIS open. Data. Input. Stream() DIS open. Input. Stream() Input.

Generic Connection Framework Connection DIS open. Data. Input. Stream() DIS open. Input. Stream() Input. Connection void close() DOS open. Data. Output. Stream() DOS open. Output. Stream() Output. Connection Stream. Connection File. Connection Socket. Connection String get. Address() String get. Local. Address() int get. Local. Port() int get. Port() HTTPConnection

Socket Communication q Sockets provide an abstraction of two-point communication q The two sides

Socket Communication q Sockets provide an abstraction of two-point communication q The two sides only read/write without concern for how data is translated (encoded) and transmitted

Socket Communication q Sockets provide an abstraction of two-point communication q The two sides

Socket Communication q Sockets provide an abstraction of two-point communication q The two sides only read/write without concern for how data is translated (encoded) and transmitted q Socket is a pair (address, port) Ø address: www. google. com, turing. cc. gettysburg. edu, 135. 24. 78. 123 Ø port: 21 (ftp), 22 (ssh), 23 (telnet), 80 (http), 101 (pop mail)

Socket Communication server (turing. cc. gettysburg. edu) client (135. 24. 78. 123) web server

Socket Communication server (turing. cc. gettysburg. edu) client (135. 24. 78. 123) web server listens on port 80

Socket Communication server (turing. cc. gettysburg. edu) request web page client (135. 24. 78.

Socket Communication server (turing. cc. gettysburg. edu) request web page client (135. 24. 78. 123) turing. cc…: 80 socket 135. 24. 78. 123: 1234 web server listens on port 80

Socket Communication server (turing. cc. gettysburg. edu) request web page client (135. 24. 78.

Socket Communication server (turing. cc. gettysburg. edu) request web page client (135. 24. 78. 123) turing. cc…: 80 socket 135. 24. 78. 123: 1234 accept request socket tuing. cc…. . : 5789 web server listens on port 80

Socket Communication server (turing. cc. gettysburg. edu) client (135. 24. 78. 123) socket tuing.

Socket Communication server (turing. cc. gettysburg. edu) client (135. 24. 78. 123) socket tuing. cc…. . : 5789 web server listens on port 80 socket 135. 24. 78. 123: 1234

Socket Communication server (turing. cc. gettysburg. edu) client (135. 24. 78. 123) socket tuing.

Socket Communication server (turing. cc. gettysburg. edu) client (135. 24. 78. 123) socket tuing. cc…. . : 5789 socket 135. 24. 78. 123: 1234 request web page web server listens on port 80 client (135. 24. 78. 567) turing. cc…: 80 socket 135. 24. 78. 567: 1024

Socket Communication server (turing. cc. gettysburg. edu) client (135. 24. 78. 123) socket tuing.

Socket Communication server (turing. cc. gettysburg. edu) client (135. 24. 78. 123) socket tuing. cc…. . : 5789 socket 135. 24. 78. 123: 1234 request web page web server listens on port 80 client (135. 24. 78. 567) turing. cc…: 80 socket 135. 24. 78. 567: 1024 accept request socket tuing. cc…. . : 8019

Socket Communication server (turing. cc. gettysburg. edu) client (135. 24. 78. 123) socket tuing.

Socket Communication server (turing. cc. gettysburg. edu) client (135. 24. 78. 123) socket tuing. cc…. . : 5789 socket 135. 24. 78. 123: 1234 client (135. 24. 78. 567) web server listens on port 80 socket tuing. cc…. . : 8019 socket 135. 24. 78. 567: 1024

Simple Server (one client) 1. Open the Server Socket 2. Wait for Client Request

Simple Server (one client) 1. Open the Server Socket 2. Wait for Client Request 3. Create Streams for Communication 4. Carry Out Communication 5. Close Communication

Simple Server (one client) 1. Open the Server Socket 1. Server. Socket server =

Simple Server (one client) 1. Open the Server Socket 1. Server. Socket server = new Server. Socket(5678); 2. Wait for Client Request 1. 3. Create Streams for Communication 4. Carry Out Communication 5. Close Communication

Simple Server (one client) 1. Open the Server Socket 1. Server. Socket server =

Simple Server (one client) 1. Open the Server Socket 1. Server. Socket server = new Server. Socket(5678); 2. Wait for Client Request 1. Socket connection = server. accept(); 3. Create Streams for Communication 4. Carry Out Communication 5. Close Communication

Simple Server (one client) 1. Open the Server Socket 1. Server. Socket server =

Simple Server (one client) 1. Open the Server Socket 1. Server. Socket server = new Server. Socket(5678); 2. Wait for Client Request 1. Socket connection = server. accept(); 3. Create Streams for Communication Output. Stream os = connection. get. Output. Stream(); Data. Output. Stream output = new Data. Output. Stream (os); 4. Carry Out Communication 5. Close Communication

Simple Server (one client) 1. Open the Server Socket 1. Server. Socket server =

Simple Server (one client) 1. Open the Server Socket 1. Server. Socket server = new Server. Socket(5678); 2. Wait for Client Request 1. Socket connection = server. accept(); 3. Create Streams for Communication Output. Stream os = connection. get. Output. Stream(); Data. Output. Stream output = new Data. Output. Stream (os); 4. Carry Out Communication 1. output. write. UTF("Hi there"); 5. Close Communication

Simple Server (one client) 1. Open the Server Socket 1. Server. Socket server =

Simple Server (one client) 1. Open the Server Socket 1. Server. Socket server = new Server. Socket(5678); 2. Wait for Client Request 1. Socket connection = server. accept(); 3. Create Streams for Communication Output. Stream os = connection. get. Output. Stream(); Data. Output. Stream output = new Data. Output. Stream (os); 4. Carry Out Communication 1. output. write. UTF("Hi there"); 5. Close Communication output. close(); os. close(); connection. close(); server. close();

Simple Server (one client) public static void main(String[] args) { // Register service on

Simple Server (one client) public static void main(String[] args) { // Register service on port 1234 Server. Socket server = new Server. Socket(1234); // Wait and accept a connection Socket connection = server. accept(); // Get a communication stream associated with the socket Output. Stream os = connection. get. Output. Stream(); Data. Output. Stream output = new Data. Output. Stream(os); // Send a string! output. write. UTF("Hi there"); // Close the connection output. close(); os. close(); connection. close(); server. close(); }

Simple Client 1. Create a Socket Connection 2. Create Streams for Communication 3. Carry

Simple Client 1. Create a Socket Connection 2. Create Streams for Communication 3. Carry Out Communication 1. 4. Close Communication

Simple Client 1. Create a Socket Connection Socket. Connection connection = (Socket. Connection)Connector. open("socket:

Simple Client 1. Create a Socket Connection Socket. Connection connection = (Socket. Connection)Connector. open("socket: //gbcs 10: 123"); 2. Create Streams for Communication 3. Carry Out Communication 4. Close Communication

Simple Client 1. Create a Socket Connection Socket. Connection connection = (Socket. Connection)Connector. open("socket:

Simple Client 1. Create a Socket Connection Socket. Connection connection = (Socket. Connection)Connector. open("socket: //gbcs 10: 5678"); 2. Create Streams for Communication Input. Stream is = connection. open. Input. Stream(); Data. Input. Stream input = new Data. Input. Stream(is); 3. Carry Out Communication 4. Close Communication

Simple Client 1. Create a Socket Connection Socket. Connection connection = (Socket. Connection)Connector. open("socket:

Simple Client 1. Create a Socket Connection Socket. Connection connection = (Socket. Connection)Connector. open("socket: //gbcs 10: 5678"); 2. Create Streams for Communication Input. Stream is = connection. open. Input. Stream(); Data. Input. Stream input = new Data. Input. Stream(is); 3. Carry Out Communication String data = new String (input. read. UTF()); 4. Close Communication

Simple Client 1. Create a Socket Connection Socket. Connection connection = (Socket. Connection)Connector. open("socket:

Simple Client 1. Create a Socket Connection Socket. Connection connection = (Socket. Connection)Connector. open("socket: //gbcs 10: 5678"); 2. Create Streams for Communication Input. Stream is = connection. open. Input. Stream(); Data. Input. Stream input = new Data. Input. Stream(is); 3. Carry Out Communication String data = new String (input. read. UTF()); 4. Close Communication is. close(); input. close(); connection. close();

Simple Client try { Socket. Connection connection = (Socket. Connection) Connector. open("socket: //gbcs 10:

Simple Client try { Socket. Connection connection = (Socket. Connection) Connector. open("socket: //gbcs 10: 1234"); Input. Stream is = connection. open. Input. Stream(); Data. Input. Stream input = new Data. Input. Stream(is); String data = new String (input. read. UTF()); is. close(); input. close(); connection. close(); } catch (. . . ) { }

Lab Exercise Client-Server Communication

Lab Exercise Client-Server Communication