Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sockets API Developing Applications using the Sockets API.

Similar presentations


Presentation on theme: "Sockets API Developing Applications using the Sockets API."— Presentation transcript:

1 Sockets API Developing Applications using the Sockets API

2 IP is the underlying Network Layer Protocol Two tranport layer protocols Both End-to-end transport protocols UDP – User Datagram Protocol Datagrams Unreliable No connection Best Effort Application must deal with loss

3 IP is the underlying Network Layer Protocol Two tranport layer protocols TCP – Transmission Control Protocol Connection Oriented Reliable Byte Stream Detects/recovers from errors Conceptually similar to file I/O

4 Sockets – two sides Every TCP/UDP link has two sides Client Server

5 Creating and destroying Sockets int socket(int protocolFamily, int type, int protocol) Returns socket handle ProtocolFamily = family of protocols to be used – PF_INET Type = type of protocol SOCK_DGRAM for UDP SOCK_STREAM for TCP Protocol = specific protocol to be used IPPROTO_UDP for UDP IPPROTO_TCP for TCP

6 Creating and destroying Sockets int close(int socket) Closes socket identified by socket returns 0 on success -1 on failure

7 Addresses See other slides

8 Connecting – client side int connect(int socket, struct sockaddr *foreignAddr, unsigned int addLength) Uses created socket to connect to foreign host/application socket = socket handle created by call to socket foreignAddr = address of the server of the type sockaddr addLength = length of the foreignAddr address

9 Communicating int send(int socket, const void *msg, unsigned int msgLength, int flags) int recv(int socket, const void *rcvBuff, unsigned int buffLen, int flags) socket = socket handle msg = pointer to outgoing message rcvBuff = buff for incoming message msgLength = N of bytes of msg to be sent buffLen = size of buffer, max byte to receive flags = control default behavior set to 0

10 TCP - Server side Server is passive sits and waits for connection from client(s) replace call to connect with listen/accept

11 Listening int listen(int socket, int qlimit) listening (and blocks) for connection from “calling” client socket = existing socket handle qlimit = max number of outstanding connect requests returns 0 if success, -1 if failure

12 Making a connection int accept(int socket, struct sockaddr *clientAddr, unsigned int *addLen) Accepts connection request socket = existing socket *clientAddr = pointer to address struct of connecting client *addLen = pointer to length of clientAddr structure


Download ppt "Sockets API Developing Applications using the Sockets API."

Similar presentations


Ads by Google