Download presentation
Presentation is loading. Please wait.
Published byPhilippa Day Modified over 9 years ago
1
Socket programming
2
Sockets are a protocol independent method of creating a connection between processes. Sockets can be either: connection based or connectionless: Is a connection established before communication or does each packet describe the destination? packet based or streams based: Are there message boundaries or is it one stream? I reliable or unreliable. Can messages be lost, duplicated, reordered, or corrupted?
3
Ports… Three categories of ports: Well-known ports : Asssigned and managed by the IANA. 0- 1,023 Registered ports : Can be registered by IANA to prevent duplication. 1,024 – 49,151 Dynamic ports : Neither controlled nor registered (Ephemeral ports).
4
Socket characteristics Socket are characterized by their domain, type and transport protocol. Common domains are: AF UNIX: address format is UNIX pathname AF INET: address format is host and port number Common types are: virtual circuit: received in order transmitted and reliably datagram: arbitrary order, unreliable Each socket type has one or more protocols. Ex: TCP/IP (virtual circuits) UDP (datagram)
5
Three styles of using accept: Iterating server. Forking server. Concurrent single server
6
Poll() Int poll(struct pollfd *, int nfds, in timeout); struct pollfd { int fd; // the socket descriptor short events; // bitmap of events we're interested in short revents; // when poll() returns, bitmap of events that occurred };
7
Differences between select() and poll() Select() can only deal with a limited number of file descriptors. Poll() is considered to be slower than select. Since poll() uses an array it becomes difficult to manage after the number of connections reaches a huge number. Select() is better for cross platform applications. All these problems in differences can be dealt with. Hence, the use of select() or poll() is more or less on the implementation.
8
Non-Blocking I/O Programs that use non-blocking I/O tend to follow the rule that every function has to return immediately, i.e. all the functions in such programs are nonblocking. Asynchronous I/O, or non-blocking I/O, is a form of input/output processing that permits other processing to continue before the transmission has finished. To make a non-blocking program, make the socket non- blocking and then the input/output file non-blocking. ioctl(sockfd, FIONBIO, (char *)&on);
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.