1 / 21
文档名称:

Network-Programming-Clients.pdf

格式:pdf   页数:21
下载后只包含 1 个 PDF 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

Network-Programming-Clients.pdf

上传人:钻石文档库 2013/9/8 文件大小:0 KB

下载得到文件列表

Network-Programming-Clients.pdf

文档介绍

文档介绍:Webcore
programming
Network Programming:
Clients
1 © 2001-2003 Marty Hall, Larry Brown
Agenda
• Creating sockets
• Implementing a work client
• Parsing data using StringTokenizer
• Retrieving files from an HTTP server
• Retrieving Web documents by using the
URL class
work Programming: Clients
Network Programming: Clients 1
Client vs. Server
• Traditional definition
– Client: User work services
– Server: Supplier work services
• Problem with traditional definition
– If there are 2 programs exchanging data, it seems unclear
– Some situations (., X Windows) seem reversed
• Easier way to remember distinction
– Server starts first. Server doesn't specify host (just port).
– Client starts second. Client specifies host (and port).
• Analogy: Company phone line
– Installing phone is like starting server
– Extension is like port
– Person who calls is the client: he specifies both host
(pany number) and port (extension)
work Programming: Clients
Client vs. Server (Continued)
• If server has to start first, why are we
covering clients before we cover servers?
– Clients are slightly easier.
– We can test clients by connecting to existing servers that
are already on the .
• Point: clients created in Java need not
communicate with servers written in Java.
– They municate with any server that accepts
socket connections (as long as they know the proper
communication protocol).
– Exception: ObjectInputStream and ObjectOutputStream
allow Java programs to plicated data structures
back and forth. Only works in Java, though.
work Programming: Clients
Network Programming: Clients 2
Steps for Implementing a Client
1. Create a Socket object
Socket client = new Socket("hostname", portNumber);
2. Create an output stream that can be used to send
info to the Socket
// Last arg of true means autoflush -- flush stream
// when println is called
PrintWriter out =
new Print