Client Server Review
A simple server works on one request at a time and cannot accept new requests until the previous one is done
bad if multiple clients must do stuff... use fork to solve this problem
Sockets
Unix Sockets - local sockets... similar to named pipes must be on the same local machine
Sockets are bidirectional
can use most file descriptor functions like write/close/read/write (NOT open)
Socket descriptors
- use integers like file descriptors
- when using sockets use 2+ descriptors
- - 1 descriptor is just to establish connections
- - 2 descriptor is for actual data transfer
- - more descriptors for more simultaneous clients
Basic functions
- socket - used to create the socket
- bind - used to name a socket SERVER FUNCTION
- listen - used to create a listen queue SERVER FUNCTION
- accept - used to accept a connection from a client socket SERVER FUNCTION
- connect - used to connect to a server CLIENT FUNCTION
- read - or recv
- write - or send
- close
Important to check for errors in C
the return value of a function says "error occured" but that is all
use errno to get the exact error description
error codes are stored in errno.h
can use strerror(errno) to get the english representation of an error number
No comments:
Post a Comment