Unformatted text preview:

ProtocolWeb ServerWeb ClientClient/Server ModelApplication ProtocolCommunications RelationshipsClient/Server RelationshipCommunications PathsTCP Comm on the Same EthernetConnection-Oriented vs Connectionless ProtocolsIPLANs Connected with WANDaytime Client IPv4 – TopDaytime Client IPv4 – BottomSocket FunctionConventionConnect Functionstruct sockaddr_inReading Data and Printing the ResultDaytime Client IPv6 - TopDaytime Client IPv6 - BottomError ConditionsWrapper FunctionerrnoMore WrappersDaytime Server IPv4 (Top)Daytime Server IPv4 (Bottom)Slide 28sockaddr_in StructureBindListenAccepttime/ctimesnprintfCloseAnalysisClient/Server Examples in TextOSI ModelOSI Layers and Internet Protocol SuiteSlide 40Why have Socket API between Session and Transport Layers?BSD Networking HistoryTest NetworksNetwork TopologyDiscovering Network TopologynetstatifconfigpingPortable Operating System Interface (POSIX)64-Bit ArchitecturesComparison of 32-Bit and 64-Bit DatatypesSpecifying TypeProtocol•Programs that communicate across a network must agree on a protocol on how they will communicate•High-level decisions must be made on which program is expected to initiate communications and when responses are expectedWeb Server•A web server is typically a long-running program called a daemon•Web server sends network messages only in response to requests from the network.Web Client•The other side of the protocol is a Web client or browser.•The browser initiates communication with the Web server.Client/Server Model•Client/Server model is used for most network communications•If the client initiates all requests, the protocol is simplified – we will use this type of protocol•More complex applications use asynchronous callback communication, where the server initiates a message to the clientApplication ProtocolClientApplication ProtocolServerCommunications Relationships•Clients normally communicate with one server at a time•Although, a browser could access several server web sites over a period of time•Server regularly communicates with several clients at a timeClient/Server RelationshipClientClientClient ServerCommunications Paths•Application communicates with TCP•TCP communicates with IP•IP communicates with datalink layer of some sort•Communication goes down the stack on one side and up on the other•Client and server are typically user processesTCP Comm on the Same EthernetUserProcessWebClientApplication ProtocolWebServerApplication LayerProtocolTCP TCP Protocol TCPTransport LayerStackWithinKernelIP IP Protocol IPNetwork LayerEthernet Ethernet Protocol EthernetDatalink LayerActual Client/Server FlowEthernet LANConnection-Oriented vs Connectionless Protocols•Transmission Control Protocol (TCP) – connection oriented•User Datagram Protocol (UDP) – Connectionless protocolIP•Protocol in use since early 1980s is IP version 4 (IPv4).•A new version IP version 6 (IPv6) was developed mid 1990s•This text covers network applications using IPv4 and IPv6LANs Connected with WAN clientapplicationserverapplication host withTCP/IP host withTCP/IPLAN LANrouter routerWANrouter router router routerDaytime Client IPv4 – Top #include "unp.h"intmain(int argc, char **argv){ int sockfd, n; char recvline[MAXLINE + 1]; struct sockaddr_in servaddr; if (argc != 2) err_quit("usage: a.out <IPaddress>"); if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) err_sys("socket error"); bzero(&servaddr, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_port = htons(13); /* daytime server */ if (inet_pton(AF_INET, argv[1], &servaddr.sin_addr) <= 0) err_quit("inet_pton error for %s", argv[1]);Daytime Client IPv4 – Bottomif (connect(sockfd, (SA *) &servaddr, sizeof(servaddr)) < 0) err_sys("connect error"); while ( (n = read(sockfd, recvline, MAXLINE)) > 0) { recvline[n] = 0; /* null terminate */ if (fputs(recvline, stdout) == EOF) err_sys("fputs error"); } if (n < 0) err_sys("read error"); exit(0);Socket Function•Returns a file descriptor•AF_INET indicates the file descriptor can communicate with any internet IP – AF_UNIX indicates the file descriptor can communicate within a single UNIX system such as Chico’s ect-unix system.•SOCK_STREAM indicates connection protocol like TCP – SOCK_DGRAM indicates connectionless protocol like UDPConventionif ( (sockfd = socket(AF_INET, SOCK_STREAM,0)) < 0)The space in between parentheses at the beginning of socket call indicates that both the return of the socket FD and testing of FD for error are performed in the if statement conditionInstead of:sockfd = socket(AF_INET, SOCK_STREAM,0);if (socketfd < 0)Connect Function•Establishes connection with server•Parameters are:–File descriptor returned by client sock function–A structure of type sockaddr_in–The size of the sockaddr_in structure•Connect associates File descriptor with communications portstruct sockaddr_in•Fields initially set to 0 by bzero•Fields are then set with information about how to communicate with server–sin_family = AF_INET–sin_port = htons(13)–inet_pton sets sin_addr to argv[1]Reading Data and Printing the Result•Notice that read and fputs are in a while loop.•Some socket systems will return all data in one read call and others will return data one byte at a time. While loop handles both cases.Daytime Client IPv6 - Top#include "unp.h"intmain(int argc, char **argv){ int sockfd, n; char recvline[MAXLINE + 1]; struct sockaddr_in6 servaddr; if (argc != 2) err_quit("usage: a.out <IPaddress>"); if ( (sockfd = socket(AF_INET6, SOCK_STREAM, 0)) < 0) err_sys("socket error"); bzero(&servaddr, sizeof(servaddr)); servaddr.sin6_family = AF_INET6; servaddr.sin6_p ort = htons(13); /* daytime server */ if (inet_pton(AF_INET6, argv[1], &servaddr.s in6_addr) <= 0) err_quit("inet_pton error for %s", argv[1]);Daytime Client IPv6 - Bottomif (connect(sockfd, (SA *) &servaddr, sizeof(servaddr)) < 0) err_sys("connect error"); while ( (n = read(sockfd, recvline, MAXLINE)) > 0) { recvline[n] = 0; /* null terminate */ if (fputs(recvline, stdout) == EOF) err_sys("fputs error"); } if (n < 0) err_sys("read error"); exit(0);Error Conditions•Important to check every function for


View Full Document

Chico CSCI 372 - Protocol

Download Protocol
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 Protocol 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 Protocol 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?