Socket Programming Computer Networks, Spring 2013
Socket Programming Computer Networks, Spring 2013
Lecture today Motivation for sockets ·What' s in a socket? Working with socket Concurrent network applications Project 1
Lecture Today • Motivation for sockets • What’s in a socket? • Working with socket • Concurrent network applications • Project 1
Wh' y Socket? How can I program a network application? Share data Send messages Finish course projects IPC -Interprocess Communication
Why Socket? • How can I program a network application? – Share data – Send messages – Finish course projects... • IPC - Interprocess Communication
Network Layering 7 Application Application pResentation Presentation 5 Session Session tRansport Transport 3 Network Network Network 2 Data link Data link Data link Physical Physical Physical
Network Layering Application Presentation Session Transport Network Data link 1 Physical 2 3 4 5 6 7 Network Data link Physical Application Presentation Session Transport Network Data link Physical
Network Layering Why layering 7 Application Application pResentation Presentation 5 Session Session tRansport Transport 3 Network Network Network 2 Data link Data link Data link Physical Physical Physical
Network Layering • Why layering? Application Presentation Session Transport Network Data link 1 Physical 2 3 4 5 6 7 Network Data link Physical Application Presentation Session Transport Network Data link Physical
Layering makes it Easier Application programmer Doesn t need to send ip packets Doesn 't need to send ethernet frames Doesnt need to know how TCP implements reliability Only need a way to pass the data down Socket is the api to access transport layer functions
Layering Makes it Easier • Application programmer – Doesn’t need to send IP packets – Doesn’t need to send Ethernet frames – Doesn’t need to know how TCP implements reliability • Only need a way to pass the data down – Socket is the API to access transport layer functions
What Lower Layer need to know? We pass the data down What else does the lower layer need to know?
What Lower Layer Need to Know? • We pass the data down. What else does the lower layer need to know?
What Lower Layer need to know? We pass the data down What else does the lower layer need to know? How to identify the destination process? Where to send the data?(Addressing What process gets the data when it is there? (Multiplexing)
What Lower Layer Need to Know? • We pass the data down. What else does the lower layer need to know? • How to identify the destination process? – Where to send the data? (Addressing) – What process gets the data when it is there? (Multiplexing)
Identify the Destination Addressing IP address hostname(resolve to iP address via dns · Multiplexing port Server socket address 208.216.181.15:80 Client socket address 128.2.194.242:3479 FTP Server (port 21) Client HttpseRver (1282194242:3479,208216181.15:80)4(port80) Connection socket pair Client host address Server host address 128.2.194.242 208.216.181.15
Identify the Destination Connection socket pair (128.2.194.242:3479, 208.216.181.15:80) HTTP Server (port 80) Client Client socket address 128.2.194.242:3479 Server socket address 208.216.181.15:80 Client host address 128.2.194.242 Server host address 208.216.181.15 FTP Server (port 21) • Addressing – IP address – hostname (resolve to IP address via DNS) • Multiplexing – port
Sockets How to use sockets Setup socket Where is the remote machine(ip address hostname What service gets the data(port) Send and receive Designed just like any other lyo in unix send--write recv-- read Close the socket
Sockets • How to use sockets – Setup socket • Where is the remote machine (IP address, hostname) • What service gets the data (port) – Send and Receive • Designed just like any other I/O in unix • send -- write • recv -- read – Close the socket