Upload
virginia-bennett
View
212
Download
0
Embed Size (px)
Citation preview
Sockets in C
2
References
Manual Pages %torch man –s 3socket … Socket, bind, listen, etc. %torch man –s 3c select
Resources section of website
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
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
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
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
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
}