DOC PREVIEW
U of I CS 438 - Introduction to Unix Network Programming

This preview shows page 1-2-3-4-29-30-31-32-33-60-61-62-63 out of 63 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Introduction to Unix Network ProgrammingHow do we Communicate?What does Alice do?What does Bob do?What about sending a TCP/IP packet?Two simplest networking programsWhat are the problems?Direction and PrinciplesSocketsNetwork Programming with SocketsOutlineClient-Server ModelSocket CommunicationClient-Server Communication ModelTCP ConnectionsTCP ServiceUDP ServicesSlide 18Addresses and DataByte OrderingByte Ordering FunctionsSocket Address StructureAddress Access/Conversion FunctionsStructure: hostentSlide 25Sockets APIUDP Connection ExampleFunctions: sendtoFunctions: recvfromSocket FunctionsSlide 31TCP Connection ExampleSocket Creation and SetupFunctions: socketFunction: bindTCP and UDP PortsFunctions: listenFunctions: acceptserverSlide 40Slide 41Slide 42Establishing a ConnectionFunctions: connectclientSending and Receiving DataSlide 47Functions: writeFunctions: readTearing Down a ConnectionFunctions: closeFunctions: shutdownAdvanced SocketsExamplesSlide 55Slide 56Slide 57Slide 58Slide 59Slide 60Slide 61Slide 62Slide 63Introduction to Unix Network ProgrammingReference: Stevens Unix Network Programming8/30/06 UIUC - CS/ECE 438, Fall 2006 2How do we Communicate?Send a mail from Alice to BobAlice in Champaign, Bob in HollywoodExample:US Postal ServiceBobChampaign, IllinoisHollywood, CaliforniaAlice8/30/06 UIUC - CS/ECE 438, Fall 2006 3What does Alice do?Bob’s address (to a mailbox)Bob’s name – in case people share mailboxPostage – have to pay!Alice’s own name and address – in case Bob wants to return a messageBob100 Santa Monica Blvd.Hollywood, CA 90028Alice200 Cornfield Rd.Champaign, IL 618208/30/06 UIUC - CS/ECE 438, Fall 2006 4What does Bob do?Install a mailboxReceive the mailGet rid of envelopeRead the messageBob100 Santa Monica Blvd.Hollywood, CA 90028Alice200 Cornfield Rd.Champaign, IL 618208/30/06 UIUC - CS/ECE 438, Fall 2006 5What about sending a TCP/IP packet?Very similar to Alice-mailing-to-BobDifferent terminologies – very confusingWe have to rememberDifferent technologiesSuppose to be better (faster, more reliable, cheaper, …)8/30/06 UIUC - CS/ECE 438, Fall 2006 6Two simplest networking programsAlicethe sending processAlice’s address: 128.174.246.177 (IP addr)Alice’s name: 12345 (port #)Bobthe receiving processBob’s address: 216.52.167.132 (IP addr)Bob’s name: 23456 (port #)int main () { int sockfd; struct sockaddr_in bob_addr, alice_addr; bzero(&bob_addr, sizeof(bob_addr)); bob_addr.sin_family = AF_INET; bob_addr.sin_addr.s_addr = 0xD834A784; bob_addr.sin_port = 23456; // do the same for alice_addr … sockfd = socket(AF_INET, SOCK_DGRAM, 0); sendto(sockfd, “hi”, strlen(“hi”), 0, &bob_addr, sizeof(bob_addr));}int main () { int sockfd, n; struct sockaddr_in bob_addr, alice_addr; char mesg[100]; bzero(&bob_addr, sizeof(bob_addr)); bob_addr.sin_family = AF_INET; bob_addr.sin_addr.s_addr = 0xD834A784; bob_addr.sin_port = 23456; sockfd = socket(AF_INET, SOCK_DGRAM, 0); bind(sockfd, &bob_addr, sizeof(bob_addr)); n= recvfrom(sockfd, mesg, 100, 0, &alice_addr, sizeof(alice_addr));}8/30/06 UIUC - CS/ECE 438, Fall 2006 7What are the problems?Message may be lostNetwork is congestedReceiver is congestedMessage may be duplicated, corruptedMultiple messages: re-orderedConcurrent connections…8/30/06 UIUC - CS/ECE 438, Fall 2006 8Direction and PrinciplesPhysicalTransportData LinkNetworkProgramminglearn to use Internet for communication (with focus on implementation of networking concepts)Principles and Conceptslearn to build network from ground up8/30/06 UIUC - CS/ECE 438, Fall 2006 9SocketsprocessTCP withbuffers,variablessockethost orserverprocessTCP withbuffers,variablessockethost orserverInternetcontrolled byapp developerprocess sends/receives messages to/from its socketsocket analogous to mailboxsending process relies on transport infrastructure which brings message to socket at receiving process8/30/06 UIUC - CS/ECE 438, Fall 2006 10Network Programming with SocketsReading: Stevens 2nd ed., Ch. 1-6 or 1st ed., Ch. 1-3, 6Sockets API: A transport layer service interfaceIntroduced in 1981 by BSD 4.1Implemented as library and/or system callsSimilar interfaces to TCP and UDPCan also serve as interface to IP (for super-user); known as “raw sockets”8/30/06 UIUC - CS/ECE 438, Fall 2006 11OutlineClient-Sever ModelTCP/UDP OverviewAddresses and DataSockets APIExample8/30/06 UIUC - CS/ECE 438, Fall 2006 12Client-Server ModelAsymmetric CommunicationClient sends requestsServer sends repliesServer/DaemonWell-known name (e.g., IP address + port)Waits for contactProcesses requests, sends repliesClientInitiates contactWaits for responseClientServerClientClientClient8/30/06 UIUC - CS/ECE 438, Fall 2006 13Socket CommunicationClient processServer processClientsocket3-wayhandshakingListeningsocketConnectionsocket8/30/06 UIUC - CS/ECE 438, Fall 2006 14Client-Server Communication ModelService ModelConcurrent:Server processes multiple clients’ requests simultaneouslySequential:Server processes only one client’s requests at a timeHybrid:Server maintains multiple connections, but processes responses sequentiallyClient and server categories are not disjointA server can be a client of another serverA server can be a client of its own client8/30/06 UIUC - CS/ECE 438, Fall 2006 15TCP ConnectionsTransmission Control Protocol (TCP) ServiceOSI Transport LayerService ModelReliable byte stream (interpreted by application)16-bit port space allows multiple connections on a single hostConnection-orientedSet up connection before communicatingTear down connection when done8/30/06 UIUC - CS/ECE 438, Fall 2006 16TCP ServiceReliable Data TransferGuarantees delivery of all dataExactly once if no catastrophic failures Sequenced Data TransferGuarantees in-order delivery of dataIf A sends M1 followed by M2 to B, B never receives M2 before M1Regulated Data FlowMonitors network and adjusts transmission appropriatelyPrevents senders from wasting bandwidthReduces global congestion problemsData TransmissionFull-Duplex byte stream8/30/06 UIUC - CS/ECE 438, Fall 2006 17UDP ServicesUser Datagram Protocol ServiceOSI Transport LayerProvides a thin layer over


View Full Document

U of I CS 438 - Introduction to Unix Network Programming

Documents in this Course
Routing

Routing

5 pages

TCP

TCP

26 pages

TROLL

TROLL

3 pages

Load more
Download Introduction to Unix Network Programming
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Introduction to Unix Network Programming and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Introduction to Unix Network Programming 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?