Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
CS 424/524: Introduction to Java Programming Lecture 25 Spring 2002 Department of Computer Science University of Alabama Joel Jones Overview • • • • Questions Brief Introduction to Networking Network Programming in Java Reading for next time Brief Introduction to Networking • Network Layers Application Presentation Session Transport Network Data Link Physical Process layer http, ftp, telnet UDP/TCP IP Ethernet 802.3 Ethernet/CAT5, modems Brief Introduction to Networking (cont.) • Packets – Address Information (header) – User’s data (payload), ~1500 bytes • Datagrams (User Datagram Protocol, UDP) – Packets sent one by one – No verification by Transport layer of receipt – stateless Brief Introduction to Networking (cont.) • Connection based (Transmission Control Protocol, TCP) – Connection established, data sent, connection closed – Packets “streamed” and acknowledged – Transport layer ensures transmission through retransmission – Has state Brief Demonstration of Differences • Datagrams • Connection-based Java Networking • World’s shortest web browser! – See handout, Browser.java • So, there is a java.net package – What are the components of the model – What classes implement which components – Details… Java Networking (cont.) • Java supports both datagram and connection-based – Datagram: DatagramSocket, DatagramPacket – Connection: URL Datagrams: DatagramSocket • Constructors – DatagramSocket() - binds to any available port – DatagramSocket(int port) - binds to specified port – DatagramSocket(int port, InetAddress laddr) bind to specified local address • Transmission – receive(DatagramPacket p) - receive a packet – send(DatagramPacket p) - send a packet Datagrams: DatagramPacket • Constructors – DatagramPacket(byte[] buf, int length) receiving – DatagramPacket(byte[] buf, int length, InetAddress, int port) - sending – DatagramPacket(byte[] buf, int offset, int length) - receiving – DatagramPacket(byte[] buf, int offset, int length, InetAddress address, int port) - sending Connection-based • What does a URL consist of? – Differs based on protocol – http: • protocol “://” hostname [ “:” port ] “/” file • http://a1.cs.ua.edu:80/cs424/MP0 – ftp: • protocol “://” user “:” password “@” hostname “:” port “/” path “;type=“ typecode • ftp://jones:[email protected]:21/cs424/Lecture01. ppt What about unsupported protocols? • Socket Further Reading • Java Tutorial on Networking – http://java.sun.com/docs/books/tutorial/network ing/index.html • Textbook, Chapter 16