Unit2 Part2
Unit2 Part2
socket()
bind()
listen()
accept()
TCP Client
socket() Block until connection from client
Connection Established
connect()
Data Request
write() read()
Process Request
Data (reply)
read() write()
end-of-file notification
close() read()
close()
Socket Function
IP address
Port number
#include <sys/socket.h>
int bind(int sockfd, const struct sockaddr *myaddr,
socklen_t addrlen);
• Servers bind to their well-known port when they
start.
#include <sys/socket.h>
int listen(int sockfd, int
backlog);
• Called after both the socket and bind function .
#include <sys/socket.h>
int accept(int sockfd, struct sockaddr
*cliaddr, socklen_t *addrlen);
#include <unistd.h>
pid_t fork(void);