Presentation is loading. Please wait.

Presentation is loading. Please wait.

TCP/IP protocols Communication over Internet is mostly TCP/IP (Transmission Control Protocol over Internet Protocol) TCP/IP "stack" is software which allows.

Similar presentations


Presentation on theme: "TCP/IP protocols Communication over Internet is mostly TCP/IP (Transmission Control Protocol over Internet Protocol) TCP/IP "stack" is software which allows."— Presentation transcript:

1 TCP/IP protocols Communication over Internet is mostly TCP/IP (Transmission Control Protocol over Internet Protocol) TCP/IP "stack" is software which allows applications to communicate over network TCP/IP support is either built into OS (e.g... UNIX) or available as an add-on

2 The TCP/IP Protocol Architecture Application is what the users see, e.g. programs such as ftp, email, web browser, telnet, etc. TCP (transmission control protocol) takes messages from the application, breaks them up into packets and sends them to the remote system where the message is put back together and passed to the application - TCP corrects for errors in transmission (e.g. due to noise) and looks after flow control (a slow system talking to a fast one). IP (Internet protocol) looks after addressing of machines (each machine has its own unique address) and routing the packets over the underlying network. Low level stuff is the Network Interface Layer connecting to the underlying network(s) - TCP/IP was developed by the USA Dept of Defence to operate over multiple unreliable local or wide area networks connecting many different types of computer systems.

3 IP provides a datagram (connectionless) transport service across the network. UDP provides applications with an end-to-end datagram (connectionless) service, packets send individually with full destination address, may not arrive, may arrive out of order, e.g. used by ping, finger, etc. TCP provides applications with a a virtual circuit (connection-oriented) communication service across the network 1.Virtual circuit set up thru network (switch tables in each router) 2.Packets sent over virtual circuit, errors fixed, in order, flow control, etc 3.Virtual circuit closed Used by most applications (error free) HTTP, FTP, POP, SMTP, etc.

4 IPAddresses Every machine on a TCP/IP network requires a unique address so it can be identified and packets routed to it. IP addresses are 32 bits in length typically written as a sequence of four 8-bit numbers (range 0 to 255), representing the decimal value of each of the address bytes. e.g. 199.182.20.17. DHCP (Dynamic Host Configuration Protocol) Machines permanently connected to the internet have a static (fixed) IP address assigned by network manager Machines which are not permanently connected may have a dynamic IP address which is assigned on connection. DHCP is the protocol for assigning dynamic IP addresses – the ISP has a range of IP addresses available which are assigned when devices connect and become free on disconnection.

5 IP Domains and Host Names Most IP hosts have both a numeric IP address and a domain name. Internet hosts use a hierarchical naming structure comprising a top-level domain (TLD), domain and subdomain (optional), and host name, e.g. www.dmu.ac.uk = 146.227.1.23 Domain Name Servers (DNS) Domain names are convenient for people, however, the name must be translated back to a numeric address for routing purposes: names and numbers are stored by a "domain name server" (DNS) Client programs may query the DNS to find a number before making a connection, e.g. UNIX nslookup command e.g. www.dmu.ac.uk = 146.227.1.23

6 Clients and servers and TCP and UDP ports To send a message to the server (e.g. to collect email) the client has to send a packet to a) a particular program, e.g. the email server b) running on a particular machine, e.g. DMU’s email server Requirement b) is satisfied by knowing the machine’s Domain Name or IP address, e.g. DMU’s email server is helios.dmu.ac.uk on IP address 146.227.1.2. However, a particular machine may be running several servers (email, ftp, www, etc.) so how is a packet delivered to the correct program, i.e. requirement a) above? This achieved by ‘ports’ via which programs communicate, i.e. servers ‘listen’ on particular ports and clients send messages to that port. When TCP/IP is running on a particular machine (with a particular IP address) TCP and UDP each have 65536 ports numbered 0 to 65535 many of which are reserved for standard services (typically 0 to 1024).

7 TCP/IP Applications

8 Client and server send simple text messages to each other to be displayed in a JTextArea In the server method main() (at end of file) 1.Creates a new Server object to create the GUI Server app = new Server(); 2. Calls the runServer method to do client communication app.runServer(); Server’s constructor creates the GUI (extends JFrame) a)JTextField enter for text input to send to client b)JTextArea display for text output A server using TCP (server.java)server.java

9 Step 1: Create a ServerSocket. server = new ServerSocket( 15000, 100 ); Step 2: Wait for a connection. connection = server.accept(); Step 3: Get input and output streams. output = new ObjectOutputStream( connection.getOutputStream() ); output.flush(); input = new ObjectInputStream(connection.getInputStream() ); Step 4: Loop - process connection receiving messages from client message = (String) input.readObject(); casts to a String, appends to display, terminates on command Step 5: Closes connection. Method runServer creates a ServerSocket, waits for client to connect and process information

10 Method sendData sends the text entered in the JTextField to the client private void sendData( String s ) { try { output.writeObject( "SERVER>>> " + s ); output.flush(); display.append( "\nSERVER>>>" + s ); } catch ( IOException cnfex ) { display.append("\nError writing object" ); } }

11 In the server method main() (at end of file) 1.Creates a new Client object to create the GUI Client app = new Client(); 2. Calls the runClient method to do server communication app.runClient(); Client’s constructor creates the GUI (extends JFrame) a)JTextField enter for text input to send to server b)JTextArea display for text output The client (client.java) connects to server and sends textclient.java

12 Step 1: Create a Socket to make connection client = new Socket(InetAddress.getByName( "127.0.0.1" ), 15000 ); First parameter is Internet address of server (localhost “127.0.0.1” in this case) and second is port number (15000) Step 2: Get the input and output streams. output = new ObjectOutputStream(client.getOutputStream() ); output.flush(); input = new ObjectInputStream(client.getInputStream() ); Step 3: Process connection – loops read messages from server message = (String) input.readObject(); until server sends terminate message Step 4: Close connection. Method runClient creates a Socket to communicate with the server

13 Method sendData sends the text entered in the JTextField to the client private void sendData( String s ) { try { output.writeObject( “CLIENT>>> " + s ); output.flush(); display.append( "\nCLIENT>>>" + s ); } catch ( IOException cnfex ) { display.append("\nError writing object" ); } }

14 To be able to handle multiple simultaneous clients a server needs to create a Thread (a lightweight process) for each client which connects The BarServer/BarClient is a simulation of a shop BarServer.java is a server which maintains a database of products in the following classesBarServer.java –Product.java – holds product barcode, contents, etcProduct.java –Inventory.java – stores a number of ProductsInventory.java BarClient.java simulates a till which sends barcodes to the server and receives product detailsBarClient.java Threaded client/server example


Download ppt "TCP/IP protocols Communication over Internet is mostly TCP/IP (Transmission Control Protocol over Internet Protocol) TCP/IP "stack" is software which allows."

Similar presentations


Ads by Google