Page 1
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Chapter 16
SocketInterface
Page 2
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
CONTENTSCONTENTS• SOME DEFINITIONS• SOCKETS• BYTE ORDERING• ADDRESS TRANSFORMATION• BYTE MANIPULATION FUNCTIONS• INFORMATION ABOUT REMOTE HOST• SOCKET SYSTEM CALLS• CONNECTIONLESS ITERATIVE SERVER
Page 3
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
CONTENTS (continued)CONTENTS (continued)• UDP CLIENT-SERVER PROGRAMS• CONNECTION-ORIENTED CONCURRENT SERVER• TCP CLIENT-SERVER PROGRAMS
Page 4
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
SOME DEFINITIONS
16.116.1
Page 5
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Figure 16-1
Data types
Page 6
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Figure 16-2
Internet address structure
Page 7
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
SOCKETS
16.216.2
Page 8
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Figure 16-3
Socket address
Page 9
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Figure 16-4
Socket structure
Page 10
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Figure 16-5
Socket types
Page 11
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
BYTE ORDERING
16.316.3
Page 12
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Figure 16-6
Big-endian byte order
Page 13
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Figure 16-7
Little-endian byte order
Page 14
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
The byte order for the TCP/IPThe byte order for the TCP/IPprotocol suite is big endian.protocol suite is big endian.
Page 15
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Figure 16-8
Bite-order transformation
Page 16
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Figure 16-9
Declarations for byte-order transformation
Page 17
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
ADDRESSTRANSFORMATION
16.416.4
Page 18
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Figure 16-10
Address transformation
Page 19
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Figure 16-11
Declarations for address transformation
functions
Page 20
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
BYTEMANIPULATION
FUNCTIONS
16.516.5
Page 21
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Figure 16-12
Declarations for byte-manipulation functions
Page 22
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
INFORMATIONABOUT REMOTE
HOST
16.616.6
Page 23
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Figure 16-13
Declaration for gethostbyname
Page 24
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Figure 16-14 Hostent structure
Page 25
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
SOCKET SYSTEMCALLS
16.716.7
Page 26
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Figure 16-15
Declaration for socket function
Page 27
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Figure 16-16
Declaration for bind function
Page 28
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Figure 16-17
Declaration for connect function
Page 29
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Figure 16-18
Declaration for listen function
Page 30
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Figure 16-19
Declaration for accept function
Page 31
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Figure 16-20
Declaration for sendto function
Page 32
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Figure 16-21
Declaration for recvfrom function
Page 33
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Figure 16-22
Declaration for read function
Page 34
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Figure 16-23
Declaration for write function
Page 35
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Figure 16-24
Declaration for close function
Page 36
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
CONNECTIONLESSITERATIVE
SERVER
16.816.8
Page 37
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Figure 16-25
Socket interfacefor connectionless
iterative server
Page 38
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
UDP CLIENT-SERVERPROGRAMS
16.916.9
Page 39
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
CONNECTION-ORIENTEDCONCURRENT SERVER
16.1016.10
Page 40
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Figure 16-26
Socket interfacefor connection-oriented
concurrent server
Page 41
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Figure 16-26 (repeated), Part I
Page 42
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Figure 16-26 (repeated), Part II
Page 43
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Figure 16-27, Part I
Clientand
Server
Page 44
McGraw-Hill ©The McGraw-Hill Companies, Inc., 2000
Figure 16-27, Part II