Sockets Basics Conectionless Protocol
Today IPC Sockets Basic functions Handed code Q & A
Interprocess Communication Mechanism to allow processes to communicate and to synchronize their actions Within the same system or different systems Best provided by messaging systems (no shared variables)
IPC types Pipes FIFOs Streams and messages Message queues, semaphores and shared memory (system V) Sockets and TLI
Sockets Communication among processes in the same system (pipes) and different systems Characteristics –Unique address –Domain dependent Types –Stream –Sequenced –Datagram –Raw Connectionless Vs connection oriented
Connectionless Oriented Socket Bind recvfrom sendto Blocks until data received from a client Process request Server Socket Bind sendto recvfrom Client
Basic functions socket (int family, int type, int protocol) : defines the socket –Address family: UNIX, internet, Xerox NS, IMP –Type: stream, datagram, raw, sequenced –Protocol argument: specify protocol (tcp, udp, icmp, etc) –Returns a socket file descriptor
Basic functions… cont Bind (int sockfd, struct sockaddr *myaddr, int addrlen) : assigns a name to an unnamed socket (“this is my adddress and any messages received for this address are to be given to me”) –sockfd: socket file descriptor –struct sockaddr: protocol specific address (family, port, address - netid) –addrlen: size of the structure –returns error if so
Basic functions… cont sendto (int sockfd, char *buff, int nbytes, int flags, struct sockaddr *to, int addrlen) : send message recvfrom (int sockfd, char *buff, int nbytes, int flags, struct sockaddr *to, int addrlen) : receive message –buff: message –nbytes: length of the message
Handed code Init_socket send_packet receive_packet get_addr_byname
Questions and Answers