Niemeyer, P (2000). Learning Java.pdf

April 29, 2018 | Author: Anonymous | Category: Documents
Report this link


Description

Copyright Table of Contents Index Full Description About the Author Reviews Examples Reader reviews Errata Learning Java Pat Niemeyer Jonathan Knudsen Publisher: O'Reilly First Edition May 2000 ISBN: 1-56592-718-4, 722 pages For programmers either just migrating to Java or already working steadily in the forefront of Java development, Learning Java gives a clear, systematic overview of the Java 2 Standard Edition. It covers the essentials of hot topics like Swing and JFC; describes new tools for signing applets; and shows how to write networked clients and servers, servlets, and JavaBeans as state-of-the-art user interfaces. Includes a CD-ROM containing example code and JBuilder for Windows and Solaris. Learning Java Preface New Developments Audience Using This Book Getting Wired Conventions Used in This Book How to Contact Us Acknowledgments 1. Yet Another Language? 1.1 Enter Java 1.2 A Virtual Machine 1.3 Java Compared with Other Languages 1.4 Safety of Design 1.5 Safety of Implementation 1.6 Application and User-Level Security 1.7 Java and the World Wide Web 1.8 Java as a General Application Language 1.9 A Java Road Map 2. A First Application 2.1 HelloJava1 2.2 HelloJava2: The Sequel 2.3 HelloJava3: The Button Strikes! 2.4 HelloJava4: Netscape's Revenge Again, in theory, just about any protocol family can be used underneath the socket layer: Novell's IPX, Apple's AppleTalk, even the old ChaosNet protocols. But in practice, there's only one protocol family people care about on the Internet, and only one protocol family Java supports: the Internet Protocol, IP. The Socket class speaks TCP, and the DatagramSocket class speaks UDP, both standard Internet protocols. These protocols are generally available on any system that is connected to the Internet. 11.1.1 Clients and Servers When writing network applications, it's common to talk about clients and servers. The distinction is increasingly vague, but the side that initiates the conversation is usually considered the client. The side that accepts the request to talk is usually the server. In the case where there are two peer applications using sockets to talk, the distinction is less important, but for simplicity we'll use this definition. For our purposes, the most important difference between a client and a server is that a client can create a socket to initiate a conversation with a server application at any time, while a server must prepare to listen for incoming conversations in advance. The java.net.Socket class represents one side of an individual socket connection on both the client and server. In addition, the server uses the java.net.ServerSocket class to listen for connections from clients. An application (or thread) acting as a server creates a ServerSocket object and waits, blocked in a call to its accept( ) method, until a connection arrives. When it does, the accept( ) method creates a Socket object the server uses to communicate with the client. A server may carry on conversations with multiple clients at once; in this case there will still be only a single ServerSocket but the server will have multiple Socket objects—one associated with each client, as shown in Figure 11.2. Figure 11.2. Clients and servers, Sockets and ServerSockets A client needs two pieces of information to locate and connect to another server on the Internet: a hostname (used to find the host's network address) and a port number. The port number is an identifier that differentiates between multiple clients or servers on the same host. A server application listens on a prearranged port while waiting for connections. Clients select the port number assigned to the service they want to access. If you think of the host computers as hotels and the applications as guests, then the ports are like the guests' room numbers. For one person to call another, he or she must know the other party's hotel name and room number. 11.1.1.1 Clients


Comments

Copyright © 2024 UPDOCS Inc.