Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
Advanced Java Session 4 New York University School of Continuing and Professional Studies Objectives • Networking Basics – Topologies, Layers, Communications • • Command line tools Network programming basics – Sockets, TCP/IP stack • Java Network Programming – – – – – • Creating sockets Implementing servers URLs and URLConnections Protocol Handlers Content Handlers Advanced concepts in Sockets – – – – Secure Sockets – Client and Server Channels (Non-Blocking I/O) UDP_ Datagrams and Sockets Multicast Sockets 2 Bus 3 Star 4 Sample Network 5 ISO stack and TCP/IP stack Application Presentation Session Transport Network Application Transport (TCP & UDP) Internet (IP) Data Link Physical ISO Reference Model Network Interface TCP Reference Model 6 Network Communications Machine A Machine B Application Application Packets Transport Transport Internet Internet Network Interface Network Interface 7 TCP/IP stack 8 IP • Java supports only IP based networks • IP (Internet Protocol) has a number of advantages over competing protocols such as AppleTalk and IPX etc. • Robust (multiple routes between any 2 points) • Cross platform 9 TCP • Layered on top of IP • Guaranteed delivery of packets “in the order in which they were sent” • Carries a fair amount of overhead 10 UDP • Layered on top of IP • Unreliable • No guarantee that packets will arrive at the destination or even arrive at all 11 IP Addresses • Every Computer is identified by a 4 byte (IPV4) number (e.g. 66.95.177.137 ) • Slow transition to IPV6 is underway which uses a 16 byte number for addresses (since JDK 1.4) • NAT and IP Masquerading allow reuse of same IP addresses in networks separated by a router/firewall 12 Multicasting • Middle ground between “unicasting” (pointto-point) and “broadcasting” (to-everybody) • Address range between 224.0.0.0 (reserved) to 239.255.255.255 13 Domain Name System • Top Level Domains – com, net, org, … are served by “ROOT” dns servers run by InterNic • All domains must be registered with Internic • Delegate model is used to allow organizations to control their own set of names 14 Sockets and Ports Source ip Source port Destination ip Destination port 15 TCP/IP Session • Source machine creates a socket and attempts to connect to a destination machine by giving its “ip” and “port” numbers • Source machine responds with ConnectionAccepted • If the destination machine is listening on that port “and” accepts this connection it responds with “request accepted” Data can now be transferred until an EOF is seen or a Network Error occurs 16 Some Useful Commands • telnet <host> <port> - connects to given host and port • netstat – shows status of TCP/IP activity • nslookup – used to look up IP Addresses of host names 17 Examples • SocketTest.java – Simple socket client • EchoServer.java – Simple Socket Server 18 Examples • ThreadedEchoServer.java – Multithreaded Socket Server – Can service multiple clients 19 The java.net package • Contains classes and interfaces that can be used to write network programs in Java • InetAddress, Inet4Address and Inet6Address • NetworkInterface class • SocketImpl class • SocketAddress (abstract) and InetSocketAddress (implements Serializable) • Socket, ServerSocket, DatagramSocket • URL, URLConnection, HttpURLConnection 20 The javax.net and javax.net.ssl packages • Contains classes and interfaces that can be used to create SSL Sockets • SocketFactory, ServerSocketFactory in javax.net • SSLSocketFactory, SSLServerSocketFactory in javax.net.ssl • SSLSocket, SSLServerSocket • HttpsURLConnection 21 java.nio and java.nio.channels • Data Buffers for storing and manipulating raw data before and after I/O • Channels for reading and writing from entities that are capable of performing I/O such as files, devices and sockets 22 More Examples • • • • HostLookup.java InterfaceLister.java PortScanner.java (uses socket factory) ChargenServer.java and ChargenClient.java (demonstrate SocketChannel and non-blocking operations on sockets) 23 UDP Examples • UDPServer.java and UDPEchoServer.java • UDPClient.java 24 Multicast Examples • MulticastSniffer.java • MulticastSender.java 25 URLConnection examples • AllHeaders.java • HttpGetter.java • FormPoster.java 26 Java Mail API • SMTPClient.java • SMTPApplet.java 27 Network Security and Applets • Can’t connect to servers other than the one it was downloaded from. • Can’t access local hard disk • Signed applets may be permitted to override the security – provided that the user permits it. 28 Thank you 29