sockets overview
play

Sockets: Overview Matt Ruffalo Adapted from content by Stuart - PowerPoint PPT Presentation

Sockets: Overview 1/13 Sockets: Overview Matt Ruffalo Adapted from content by Stuart Morgan, 2003 April 9, 2013 Sockets: Overview 2/13 Overview Sockets from 10,000 feet communicating across an arbitrary networks (LAN, Internet, etc.)


  1. Sockets: Overview 1/13 Sockets: Overview Matt Ruffalo Adapted from content by Stuart Morgan, 2003 April 9, 2013

  2. Sockets: Overview 2/13 Overview Sockets from 10,000 feet communicating across an arbitrary networks (LAN, Internet, etc.) without worrying about hardware. same API straightforward and uniform. ▶ Overall idea: provide a reasonably high-level method of ▶ Lets you use TCP or UDP (more on those later) with the ▶ A few ugly API details, but in the abstract they are very

  3. Sockets: Overview 3/13 ISO/OSI Model ISO/OSI Networking Model 7 layers 7 Application 6 Presentation 5 Session 4 Transport 3 Network 2 Data Link 1 Physical Useful in theory, but network communication doesn’t actually work this way

  4. Sockets: Overview 4/13 ISO/OSI Model ISO/OSI Networking Model 7 layers below it physical media a wire ▶ In principle, a layer only has to deal with the one directly ▶ Transport layer relies on network layer for host addressing ▶ Network layer uses data link layer to communicate over ▶ Data link layer doesn’t care about sending voltage signals over

  5. Sockets: Overview 5/13 ISO/OSI Model ISO/OSI Networking Model 7 layers layers (transport and network) ▶ Real Internet isn’t implemented this way ▶ Top three layers are blended together ▶ Unix socket communication deals with the third and fourth

  6. Sockets: Overview 6/13 From 100 feet A few more details Connections or not? connection-oriented (TCP) and connectionless (UDP). ▶ There are two models of socket programming: ▶ Each has strengths in different applications ▶ Sockets are identified the same in both protocols: (IP, port) ▶ Different services use different ports by convention ▶ HTTP: 80, SMTP: 25, SSH: 22, . . . ▶ Sockets are “bound” to port numbers on creation

  7. Sockets: Overview connection Read and write data with read and write Read and write data with read connect with connection a Request accept with a 7/13 Establish listen Set up a connection queue with bind Bind the socket to a port with Create a socket with socket Create a socket with socket Client Server Connection-oriented paradigm Connection-oriented and write

  8. Sockets: Overview 8/13 Connectionless Connectionless paradigm Server Client Create a socket with socket Create a socket with socket Bind the socket to a port with bind Bind the socket to a port with bind Send and receive data with recvfrom and sendto Send and receive data with recvfrom and sendto

  9. Sockets: Overview 9/13 Notes A few things to note: each of these commands does, which makes the models fairly easy to use. commands certainly differ from language to language, the overview above is fairly constant from language to language. ▶ The commands have intuitive names. It’s fairly clear what ▶ Parameters are not so straightforward ▶ Not a C-specific model. Although the details of these ▶ Python and Java work in almost exactly the same way.

  10. Sockets: Overview 10/13 TCP vs. UDP Main difference: reliability of data stream Say you are standing in the Strosacker balcony, and your friend is on the stage, and you want to pass notes (don’t ask why you can’t just shout, it’s an analogy) down to your friend. Each of you holds one end tight, and to pass a note down you punch a hole in it, and thread it onto the string, where gravity pulls it down to your friend, who will get every note, all in the order that you sent them. ▶ To simulate TCP, you get a long string, and throw one end

  11. Sockets: Overview 11/13 TCP vs. UDP Main difference: reliability of data stream Say you are standing in the Strosacker balcony, and your friend is on the stage, and you want to pass notes (don’t ask why you can’t just shout, it’s an analogy) throw them to your friend. Now, most will get there (assuming you make good airplanes), but occasionally, some will go off in a random direction, or crash right away, so your friend never gets them. What’s more, some of them may do a lot of looping and hovering, and take a long time to arrive, while others will go directly, so there’s no guarantee they will get there in the order you sent them. ▶ For UDP, you write all your messages on paper airplanes and

  12. Sockets: Overview exit() close(clnt) write(clnt, "response") if (request starts with "GET") request=read(clnt) void serveRequest(clnt) { } } } serveRequest(clnt) 12/13 if (fork() == 0) { clnt = accept(srv) while (1) { listen(srv) bind(srv, 80) srv = socket() main { Server Client/Server Pseudocode }

  13. Sockets: Overview 13/13 Client/Server Pseudocode Client main { client = socket() write(client, "GET /index.html HTTP/1.0") read(client, response) printf(response) close(client) } connect(client, hostname, 80)

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend