Presentation is loading. Please wait.

Presentation is loading. Please wait.

RGEC MEERUT(IWT CS703) 1 Java Networking RGEC Meerut.

Similar presentations


Presentation on theme: "RGEC MEERUT(IWT CS703) 1 Java Networking RGEC Meerut."— Presentation transcript:

1 RGEC MEERUT(IWT CS703) 1 Java Networking RGEC Meerut

2 RGEC MEERUT 2 Open System Connection The OSI model describes the architecture for inter computer Communications. Data moves down the layers of the source computer,across a physical medium, then back up the layers of the destination computer

3 RGEC MEERUT(IWT CS703) 3 Networks/Protocols Computer network – A set of computers using common protocols to communicate over connecting transmission media. Protocol – A formal description of message formats and the rules two or more machines follow to exchange messages. – Transmission Control Protocol/Internet Protocol (TCP/IP) is a very popular protocol in use today.

4 RGEC MEERUT(IWT CS703) 4 Socket Based Communication Programs running on separate machines can communicate with each other through designated TCP/IP sockets Sockets are the endpoints of logical connections between two hosts and can be used to send and receive data Socket communication in Java works similarly to I/O Operations

5 RGEC MEERUT(IWT CS703) 5 Stream Sockets Stream sockets use TCP (Transmission Control Protocol) for data transmission. TCP is lossless and reliable because it can detect lost transmissions and resubmit them. All data sent is received in the same order it was sent. A stream of 8-bit bytes is exchanged across a TCP connection. Connections provided by TCP allow concurrent transfer in both directions. Such connections are called full duplex. A fitting analogy is a telephone connection with a dedicated link. With the chat project, all conversations between users are handled using stream sockets.

6 RGEC MEERUT(IWT CS703) 6 Connection –Oriented Transfer

7 RGEC MEERUT(IWT CS703) 7 Datagram Sockets Datagram sockets use UDP (User Datagram Protocol) for data transmission. UDP cannot guarantee that packets are not lost, or not received in duplicate, or received in the order they were sent. An analogy is the sending of letters through the post office – Although you don’t get duplicate letters. With the chat project, the broadcasting of the registered user list is handled using datagram sockets.

8 RGEC MEERUT(IWT CS703) 8 Connectionless Transfer

9 RGEC MEERUT(IWT CS703) 9 Client/Server Computing

10 RGEC MEERUT(IWT CS703) 10 Server Socket To establish a server, you need to create a server socket and attach it to a port where the server will listen for connections – Port numbers range from 0 to 65536 Ports 0 to 1024 are reserved for privileged services ftp runs on port 21 sendmail runs on port 25 http runs on port 80 To create a server socket on port 8000: // running on server: rgec.edu try { ServerSocket servSocket = new ServerSocket(8000); } catch (java.net.BindException) { // port is already in use}

11 RGEC MEERUT(IWT CS703) 11 Client Sockets After a server socket is created, the server can listen for client connections using accept() // running on server: rgec.edu Server socket = servSocket.accept(); The statement blocks until a client connects to the server socket using the server host name // running on client: ikaruga.cs.rit.edu Socket socket = new Socket(“rgec.edu”, 8000); alternatively, you can specify the IP address in a string: “129.21.36.165”

12 RGEC MEERUT(IWT CS703) 12 Client Socket If you provide a host name instead of an IP when creating a socket, Java will query a Domain Name Server to do the translation. The hostname localhost refers to the machine on which a client is running “There’s no place like 127.0.0.1 ”

13 RGEC MEERUT(IWT CS703) 13 Data Transmission Through Sockets

14 RGEC MEERUT(IWT CS703) 14 Data Transmission Through Sockets The socket returns an InputStream and OutputStream for reading and writing bytes. InputStream is =socket.getInputStream(); OutputStream os = socket.getOutputStream(); For efficiency, wrap those streams to do binary I/O: DataInputStream input = new DataInputStream(is); DataOutputStream output = new DataOutputStream(os);

15 RGEC MEERUT(IWT CS703) 15 InetAddress Use InetAddress to find the hostname and IP of a client connecting to a server. InetAddress inetAddress = socket.getInetAddress(); System.out.println(“Client’s host name is “ + inetAddress.getHostName()); System.out.println(“Client’s IP address is “ +inetAddress.getHostAddress()); You can create an instance of InetAddress using the static method getByName(String). InetAddress address =InetAddress.getByName(“rgec.edu”);

16 RGEC MEERUT(IWT CS703) 16 Client/Server Example Write a client program which sends the radius of a circleto a server program, which computes the area and then sends the result back to the client

17 RGEC MEERUT(IWT CS703) 17 Port ProtocolPort Number Datatime 13 FTP –data20 FTP –Control21 Telnet23 SMTP25 HTTP80 POP3110 NNTP119


Download ppt "RGEC MEERUT(IWT CS703) 1 Java Networking RGEC Meerut."

Similar presentations


Ads by Google