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

This preview shows page 1-2-3-4-24-25-26-50-51-52-53 out of 53 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 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 53 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 53 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 53 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 53 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 53 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 53 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 53 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 53 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 53 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 53 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 53 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?Direction and PrinciplesSocketsNetwork Programming with SocketsClient-Server ModelClient-Server Communication ModelPowerPoint PresentationSlide 12TCP ConnectionsTCP ServiceUDP ServicesSlide 16AddressesAddresses and DataAddress Access/Conversion FunctionsStructure: hostentChoose portByte OrderingByte Ordering FunctionsSocket addressSocket Address StructureConnecting the socketServerAddress specificationbindListenAcceptTCP Connection ExampleUDP Connection ExampleFunctions: sendtoFunctions: recvfromTCP and UDP PortsReviewConcurrent Server FlowchartFork Concurrent ServerFork callThreaded serverPosix Threads (pthreads)pthreads AttributesSlide 44pthread Error Handlingpthread Creationpthread CleanupSlide 48pthreads vs. forkMultithreading-Safe FunctionsExample: getpwuidgetpwuid_rAnnouncementsIntroduction to Unix Network ProgrammingReference: Stevens Unix Network Programming8/29/07 UIUC - CS/ECE 438, Fall 2007 2How do we Communicate?Send a mail from Alice to BobAlice in Champaign, Bob in HollywoodExample:US Postal ServiceBobChampaign, IllinoisHollywood, CaliforniaAlice8/29/07 UIUC - CS/ECE 438, Fall 2007 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/29/07 UIUC - CS/ECE 438, Fall 2007 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/29/07 UIUC - CS/ECE 438, Fall 2007 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/29/07 UIUC - CS/ECE 438, Fall 2007 6Direction and PrinciplesPhysicalTransportData LinkNetworkProgramminglearn to use Internet for communication (with focus on implementation of networking concepts)Principles and Conceptslearn to build network from ground up8/29/07 UIUC - CS/ECE 438, Fall 2007 7SocketsprocessTCP 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/29/07 UIUC - CS/ECE 438, Fall 2007 8Network Programming with SocketsReading: Stevens 2nd or 3rd 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/29/07 UIUC - CS/ECE 438, Fall 2007 9Client-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/29/07 UIUC - CS/ECE 438, Fall 2007 10Client-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/29/07 UIUC - CS/ECE 438, Fall 2007 11int main(int argc, char **argv) { int sockfd = socket(PF_INET, SOCK_STREAM, 0); struct hostent * he = gethostbyname(argv[1]); struct sockaddr_in their_addr; their_addr.sin_addr = *((struct in_addr *)he->h_addr); their_addr.sin_port = htons(atoi(argv[2])); their_addr.sin_family = AF_INET; memset(their_addr.sin_zero, ‘\0’, sizeof their_addr.sin_zero); connect(sockfd, (struct sockaddr *) their_addr, sizeof their_addr); write(sockfd, “GET /\r\n”, strlen(“GET /\r\n”)); while (1) { char buf[100]; int len = read(sockfd, buf, 100); if (len <= 0) { close(sockfd);return 0; } else { write(1, buf, len); } }}8/29/07 UIUC - CS/ECE 438, Fall 2007 12Sockets int sockfd = socket(PF_INET, SOCK_STREAM, 0);Creates a new socketSOCK_STREAM = TCPSOCK_DGRAM = UDP8/29/07 UIUC - CS/ECE 438, Fall 2007 13TCP 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/29/07 UIUC - CS/ECE 438, Fall 2007 14TCP 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/29/07 UIUC - CS/ECE 438, Fall 2007 15UDP ServicesUser Datagram Protocol ServiceOSI Transport LayerProvides a thin layer over IP16-bit port space (distinct from TCP ports) allows multiple recipients on a single host8/29/07 UIUC - CS/ECE 438, Fall 2007 16UDP ServicesUnit of TransferDatagram (variable length packet)UnreliableNo guaranteed deliveryDrops packets silentlyUnorderedNo guarantee of maintained order of deliveryUnlimited TransmissionNo flow control8/29/07 UIUC - CS/ECE 438, Fall 2007 17Addressesstruct hostent * he = gethostbyname(argv[1]);struct sockaddr_in their_addr; their_addr.sin_addr = *((struct in_addr *)he->h_addr);Look up destination host name8/29/07 UIUC - CS/ECE 438, Fall 2007 18Addresses and DataInternet domain namesHuman readableVariable lengthEx: sal.cs.uiuc.eduIP addressesEasily handled by routers/computersFixed lengthSomewhat geographicalEx: 128.174.252.2178/29/07 UIUC - CS/ECE 438, Fall


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?