Академический Документы
Профессиональный Документы
Культура Документы
int bind(int s, const struct sockaddrr *name, int namelen) is called to bind a path or
internet address to a socket.
-Unix Domain:
- #include <sys/socket.h>
-------------int bind(int s, (struct sockaddr *)&addr, int namelen)
-
#inlcude <sys/socket.h>
-------------int bind(int s, (struct sockaddr_un *)&addr, length)
-Internet Domain
- #include <netinet/in.h>
-------------bind(sd, (struct sockaddr *)&addr, length)
For a SOCK_STREAM socket, the sever call int listen(int s, int backlog) , which specifies
how many connection requests can be queued.
A client initiates connection to the servers socket by a call to int connect(int s, struct
sockaddr *name, int namelen).
If the clients socket is unbound, at the time of connect call, the system automatically selects
and binds a name to the socket. For a SOCK_STREAM socket, the server calls accept(3N) to
complete the connection.
6. Datagram Sockets
Datagram socket does not require that a connection ne established. Each message carries
the destination address. If a particular local address is needed a call to bind() must precede
data transfer.
- Data is sent through sendto() and sendmsg().
- To receive messages recvfrom() and recvmsg().
- Note: recv() requires one buffer for receiving the message. recvfrom() requires two
buffers, one for receiving message and other to receive source address.
- Datagram sockets can also use connect() to connect to a specified address.
When this is done, send() and recv() are used to send and receive message.
7. Socket options:
- getsocketopt()
- setsocketopt()
- level = SOL_SOCKET