The Transport Layer Socket Programming CE 306
Application to TCP Interface process sends/receives messages to/from its socket
Berkley Socket Primitives for TCP
TCP Socket: Overall Structure
UDP Socket: Overall Structure
Bridge Between App and TCP
Binding to Server
Server Waiting for Clients
Server Accepting Client Requests
TCP Data Exchange
Send() and Receive() Variants
UDP: Data Exchange
Terminate the Connection
Resolving Server and Client Addresses
Gethostbyname(): Sample Call
Example: UDP Client
TCP: Simple ECHO Client #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h>
TCP: Simple ECHO Server #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h>
Example Code