Académique Documents
Professionnel Documents
Culture Documents
Manjunath.
What is a socket?
End point, of a bidirectional inter process communication flow across internet protocol based computer network. Interface between an application and transport layer. Socket address is a combination:
IP address Port Protocol (?)
Stream sockets & Datagram sockets SOCK_STREAM , SOCK_DGRAM.
Socket Structures
What is the size of IPv4 network address?
32 bit
Byte Order
Functions to convert from host to network byte order and vice versa. htonl, htons, ntohl, ntohs
Listens or waits for connect requests. Accept incoming requests directed to this socket.
TCP Socket
Assign local port address to socket.
Socket API
Socket Programming
1. 2. 3. 4. 5. 6. 7. 8. 9. 10.
socket bind connect listen accept send,recv sendto, recvfrom close, shutdown getpeername gethostname
UDP Socket
Concurrency
Ability to handle more than one client at a time. Use inherent operating system multi tasking capabilities.
Fork-exec
# include <unistd.h> pid_t fork(void); //0 in child, process id, -1 on error.
Called once, returns twice. If success returns process ID to parent , and returns 0 to child. Child can always get parent id by getppid. Forking is copying (calling). And the clone calls exec to make newly executed program. When child is done executing it process runs exit. Parent must be alive until child is done with process / makes itself into new program.
fork
Thank you