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 Session Transport Network Data Link Presentation Physical Ethernet Ethernet/CAT5, modems IP UDP/TCP Process layer http, ftp, telnet
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 –ftp: protocol “://” user “:” password hostname “:” port “/” path “;type=“ typecode ppt
What about unsupported protocols? Socket
Further Reading Java Tutorial on Networking – ing/index.htmlhttp://java.sun.com/docs/books/tutorial/network ing/index.html Textbook, Chapter 16