Lecture Notes for Client-Server Interfaces
6 February 2001 - Clients
- simpler than servers - one request-response, non privileged access
- not simpler - recovery from failures
- where's that server - well known or discovered - flexibility (no
hardwiring addresses), cost (don't broadcast over wans), anycasting
(property based choice)
- what address format - domain names or ip addresses; only ip addresses
exist
- domain name translation - given a domain name, get the associated ip
address;
gethostbyname()
- there's a similar problem with ports -
getservbyname()
; but what
are the service names; /etc/services
, ypcat services
,
rfc
1700
- don't forget the byte ordering
- protocol numbering -
getprotobyname()
; I've never used this
- the client algorithm for tcp
- create a socket
- find a local port number - not usually necessary; let the operating
system pick
- picking the ip address - multi-homed hosts; a good choice requires
routing information; let the os do it
- connect to the server - resolve the local endpoint if necessary
- communicate -
send()
and recv()
are like read()
and
write()
except for an options argument; oob data
- and remember when reading server data - tcp doesn't respect message
boundaries; keep reading until you've got enough
- close - don't forget duplex traffic
- the client algorithm for udp
- about the same as tcp
- connecting to the server isn't necessary, but convenient - can use
read()
and write()
; otherwise, must give the server endpoint
- data transfer is message oriented - easier
- partial closing isn't as useful - no shut-down handshake
- however, don't forget to deal with best effort delivery - lost
packets, corrupted packets, out of order packets, duplicated packets;
this is hard to do well.
This page last modified on 1 February 2001.