sockets in c. 2 references manual pages %torch man –s 3socket … socket, bind, listen, etc....
TRANSCRIPT
![Page 1: Sockets in C. 2 References Manual Pages %torch man –s 3socket … Socket, bind, listen, etc. %torch man –s 3c select Resources section of website](https://reader036.vdocuments.us/reader036/viewer/2022083005/56649f295503460f94c41c25/html5/thumbnails/1.jpg)
Sockets in C
![Page 2: Sockets in C. 2 References Manual Pages %torch man –s 3socket … Socket, bind, listen, etc. %torch man –s 3c select Resources section of website](https://reader036.vdocuments.us/reader036/viewer/2022083005/56649f295503460f94c41c25/html5/thumbnails/2.jpg)
2
References
Manual Pages %torch man –s 3socket … Socket, bind, listen, etc. %torch man –s 3c select
Resources section of website
![Page 3: Sockets in C. 2 References Manual Pages %torch man –s 3socket … Socket, bind, listen, etc. %torch man –s 3c select Resources section of website](https://reader036.vdocuments.us/reader036/viewer/2022083005/56649f295503460f94c41c25/html5/thumbnails/3.jpg)
3
Java…
Java is a high-level language (HLL) It does a lot of work for the
programmer It hides much of the complexity of n/w
programs This can be very good, but not when
you need to understand what is happening in your programs
![Page 4: Sockets in C. 2 References Manual Pages %torch man –s 3socket … Socket, bind, listen, etc. %torch man –s 3c select Resources section of website](https://reader036.vdocuments.us/reader036/viewer/2022083005/56649f295503460f94c41c25/html5/thumbnails/4.jpg)
4
… and C
C is not exactly a HLLIt has many features that are close to the operating system and processorYet if it is used carefully, with standard libraries, etc., It can be portableIt can also be an unholy mess
![Page 5: Sockets in C. 2 References Manual Pages %torch man –s 3socket … Socket, bind, listen, etc. %torch man –s 3c select Resources section of website](https://reader036.vdocuments.us/reader036/viewer/2022083005/56649f295503460f94c41c25/html5/thumbnails/5.jpg)
5
Steps to Make a Server Socket
1. Make a socketLike opening a file
2. Bind a socketAttach it to a specific port
3. Tell it to accept connections(for stream sockets only)
4. Receive data into a buffer
![Page 6: Sockets in C. 2 References Manual Pages %torch man –s 3socket … Socket, bind, listen, etc. %torch man –s 3c select Resources section of website](https://reader036.vdocuments.us/reader036/viewer/2022083005/56649f295503460f94c41c25/html5/thumbnails/6.jpg)
6
Socket Descriptor Sets
Sockets in C are in groups Called fd_sets (file descriptor sets) The O/S will send a signal when one
of the sockets in your fd_set has data to read
We use these in the accept loop
![Page 7: Sockets in C. 2 References Manual Pages %torch man –s 3socket … Socket, bind, listen, etc. %torch man –s 3c select Resources section of website](https://reader036.vdocuments.us/reader036/viewer/2022083005/56649f295503460f94c41c25/html5/thumbnails/7.jpg)
7
The Accept Loop in C
While (1) { clear all flags set flags to say which sockets to monitor wait for accept() to return read data from socket or sockets
receive send Close
}