Java Networking (16) - COP 3330: Object-Oriented...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
COP 3330: Java Networking Page 1 © Dr. Mark Llewellyn COP 3330: Object-Oriented Programming Summer 2011 Java Networking Department of Electrical Engineering and Computer Science Computer Science Division University of Central Florida Instructor : Dr. Mark Llewellyn markl@cs.ucf.edu HEC 236, 407-823-2790 http://www.cs.ucf.edu/courses/cop3330/sum2011
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
COP 3330: Java Networking Page 2 © Dr. Mark Llewellyn Java Networking Networking is tightly integrated in Java. The Java API provides the classes for creating sockets to facilitate program communications over the Internet. Sockets are the endpoints of logical connections between two hosts and can be used to send and receive data. Java treats socket communication similar to the way it treats I/O operations; thus applications can read from or write to sockets as easily as they can read from or write to files.
Background image of page 2
COP 3330: Java Networking Page 3 © Dr. Mark Llewellyn Java Networking The Internet Protocol (IP) is a low-level protocol for delivering data from one computer to another across the Internet in packets. Two higher-level protocols used in conjunction with IP are the Transmission Control Protocol (TCP) and the User Datagram Protocol (UDP). TCP enables two hosts to establish a connection and exchange streams of data. TCP guarantees that all packets sent are delivered in the same order in which they were sent. UDP is a low-overhead, connectionless, host-to-host protocol that allows a datagram to be sent from one host to another. No connection is established and no guarantees are offered.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
COP 3330: Java Networking Page 4 © Dr. Mark Llewellyn Java Networking Network programming typically involves a server and one or more clients. The client sends requests to the server, and the server responds to those requests. The client begins by attempting to establish a connection to the server. The server can accept or deny the connection. Once a connection is established, the client and the server communicate through sockets.
Background image of page 4
COP 3330: Java Networking Page 5 © Dr. Mark Llewellyn Server Sockets To establish a server, you need to create a server socket and attach it to a port, which is where the server will listen for connections. The port identifies the TCP service on the socket. Port numbers range from 0 to 65536 (2 16 ), but most OS reserve port numbers 0 to 1024 for privileged services. For example, email servers run on port 25, and the Web server usually runs on port 80. You can choose any port number that is not currently used by any other process.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
COP 3330: Java Networking Page 6 © Dr. Mark Llewellyn Server Sockets The following statement creates a server socket named serverSocket : ServerSocket serverSocket = new ServerSocket(portNumber); Example: ServerSocket server = new ServerSocket(8000); Attempting to create a server socket on a port already in use would cause a java.net.BindException.
Background image of page 6
COP 3330: Java Networking Page 7 © Dr. Mark Llewellyn Server Sockets
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 39

Java Networking (16) - COP 3330: Object-Oriented...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online