![]() |
![]() |
![]() |
![]() |
![]() |
|
The sockaddr_in structure type is a complex structure containing
embedded structures. The purpose of sockaddr_in objectssuch as
server_addr and client_addris to hold information about
the socket's type, the computer's Internet address, and the socket's
number. All this information is established in assignment statements such
as the following, in which "128.52.36.4" is the Internet address of
the server computer; 6022 is a port number, selected by the author
of the server program; and AF_INET is a macro symbol that identifies
the socket as one that is intended to provide a service over the Internet:
server_addr.sin_addr.s_addr = inet_addr ("128.52.36.4");
server_addr.sin_family = AF_INET;
server_addr.sin_port = 6022;
Note that the port number must be selected that is different from any port number previously assigned by the operating system or other server program; generally, an integer above 6000 avoids conflict with port numbers assigned by the operating system.