150 likes | 475 Views
Generic Transport Service Primitives. Listen notify Transport layer a call is expected Connect establish Transport layer connection Send (or Write) Receive (or Read) Both could be connectionless Disconnect (or Close). Berkeley Sockets.
E N D
Generic Transport Service Primitives • Listen • notify Transport layer a call is expected • Connect • establish Transport layer connection • Send (or Write) • Receive (or Read) • Both could be connectionless • Disconnect (or Close)
Berkeley Sockets • ‘Sockets’ are one of the 2 major Unix network programming application programming interfaces. • The other is the System V Transport Layer Interface (TLI). • Sockets are biased towards Unix and C. • Good references are Doug Comer’s Vol III • both of them!
Unix File I/O • Unix treats a file as a ‘stream of bytes’ • API calls: open, creat, read, write, lseek, close • All operate on file descriptors • File descriptors are int’s, but represent a more complex structure
1.2.3.4 23 2.3.4.5 2000 “Big Picture” “Server” “Client” User Space Process User Space Process Program Program sd sd OS Space IP Port OS Space IP Port L 2.3.4.5 2000 L R 1.2.3.4 23 R duplicated Socket Socket
Socket I/O • Transport layer also provides ‘stream of bytes’ type service to the upper layers • API calls: • socket: Initialize data structure • bind: set addresses • listen: specify a queue • accept: wait for connection • connect: initiate a connection • read, write, recv, send: transfer data • close, shutdown: terminate connection • recvfrom, sendto: datagrams
socket() bind() listen() read() accept() socket() bind() connect() write() Overview -- connection Server server blocks Client Optional(!!)
socket() bind() sendto() socket() bind() sendto() recvfrom() Overview -- connectionless Server server blocks recvfrom() Client
Socket Paradigm • Setup is ‘client/server’ because someone has to start the conversation • BUT, communication is bidirectional (either end can read or write) • Sockets (in Unix) are multiprotocol: • TCP/IP, UNIX, XNS {address families}
Server Types • Iterative • Receive request, process it, go to next on queue • Best in connection-less environment • Concurrent • Receive request, fork process, reset socket • Best when extended interaction is needed
Socket ‘Details’ • If you don’t want to block on a read, look at the select system call. • You’ll need the following includes: • #include <sys/types.h> • #include <sys/socket.h> • Program examples are available on net.