java networking - part 3

java networking - part 3 - COP 4610L: Applications in the...

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

View Full Document Right Arrow Icon
COP 4610L: Java Networking Part 3 Page 1 Mark Llewellyn © COP 4610L: Applications in the Enterprise Fall 2006 Java Networking and the Internet – Part 3 COP 4610L: Applications in the Enterprise Fall 2006 Java Networking and the Internet – Part 3 School of Electrical Engineering and Computer Science University of Central Florida Instructor : Mark Llewellyn markl@cs.ucf.edu CSB 242, 823-2790 http://www.cs.ucf.edu/courses/cop4610/fall2006
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 4610L: Java Networking Part 3 Page 2 Mark Llewellyn © More Details on Establishing a Server Using Stream Sockets •S t e p 1 is to create a ServerSocket object. Invoking a ServerSocket constructor such as, ServerSocket server = new ServerSocket (portNumber, queueLength); registers an available TCP port number and specifies the number of clients that can wait to connect to the server (i.e., the queue length).
Background image of page 2
COP 4610L: Java Networking Part 3 Page 3 Mark Llewellyn © More Details on Establishing a Server Using Stream Sockets (cont.) The port number is used by the clients to locate the server application on the server computer. This is often called the handshake point. If the queue is full, the server refuses client connections. The constructor establishes the port where the server waits for connections from clients – a process known as binding the server to the port. Each client will ask to connect to the server on this port. Only one application at a time can be bound to a specific port on the server.
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 4610L: Java Networking Part 3 Page 4 Mark Llewellyn © More Details on Establishing a Server Using Stream Sockets (cont.) Port numbers can be between 0 and 65,535. Most OS reserve port numbers below 1024 for system services such as email, and Internet servers. Generally, these ports should not be specified as connection ports in user programs. In fact, some OS require special access privileges to bind to port numbers below 1024. Programs manage each client connection with a Socket object.
Background image of page 4
COP 4610L: Java Networking Part 3 Page 5 Mark Llewellyn © More Details on Establishing a Server Using Stream Sockets (cont.) •I n Step 2 , the server listens indefinitely (is said to block ) for an attempt by a client to connect. To listen for a client connection, the program calls ServerSocket method accept, as in, Socket connection = server.accept(); which returns a Socket when a connection with a client is established. The Socket allows the server to interact with the client. The interactions with the client actually occur at a different server port from the handshake port. This allows the port specified in Step 1 to be used again in a multi-threaded server to accept another client connection. We’ll see an example of this later in this set of notes.
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 4610L: Java Networking Part 3 Page 6 Mark Llewellyn © More Details on Establishing a Server Using Stream Sockets (cont.) •I n Step 3 , the OutputStream and InputStream objects that enable the server to communicate with the client by sending and receiving bytes are established.
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 60

java networking - part 3 - COP 4610L: Applications in the...

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

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