Presentation is loading. Please wait.

Presentation is loading. Please wait.

Client Software Design Objectives: Understand principles of C/S design, with focus on clients Review Windows implementations of Socket functions.

Similar presentations


Presentation on theme: "Client Software Design Objectives: Understand principles of C/S design, with focus on clients Review Windows implementations of Socket functions."— Presentation transcript:

1 Client Software Design Objectives: Understand principles of C/S design, with focus on clients Review Windows implementations of Socket functions

2 CS431-cotter2 Architectural Objectives for C/S Partition applications across multiple machines –better utilization of computing resources Place user interaction portion of application closer to the user (client) –Better utilization of network bandwidth. Share server resources among many clients –Improve efficiency / utilization of resources –Synchronize use of shared resources –Control / manage access to shared resources

3 CS431-cotter3 C/S Architecture Application Client Server

4 CS431-cotter4 Example C/S Applications File Servers –C/S application used to locate and retrieve remote files Database Applications –C/S used to present database queries to remote db Groupware –C/S used to share messages among group members Web Server –C/S used to query web server for web site information, pages.

5 CS431-cotter5 2-Tier vs. 3-Tier C/S Design 3-Tier design extends distribution of application across more levels / platforms. ClientLocal ServerEnterprise Server Local DatabaseEnterprise Database App. ServerDatabase Server

6 CS431-cotter6 Client Software Design Issues Identifying Server Location –Command Line Argument –User query –Embedded (fixed) server ID Parsing Address Argument –domain name vs. IP address format Look up domain name –hptr = gethostbyname( example_name) –IP addr in hptr --> h_addr; Network byte order vs. local byte order

7 CS431-cotter7 TCP Client Algorithm Find IP address and port number of server Allocate a socket Allow TCP to choose an arbitrary, unused local port Connect the socket to the server Communicate with server (application level) Close connection

8 CS431-cotter8 TCP Client Algorithm Issues Chose a local Port number –allow connect to select port –[could use bind ( ) if needed] Identify local IP address –allow connect to specify local IP address –use gethostname ( ) –use gethostbyname ( )

9 CS431-cotter9 TCP Client Algorithm Issues Client / Server Communications –request / response interaction –write / read (send / recv) Single write may require multiple reads –response may be segmented –continue appending reads until return length = 0

10 CS431-cotter10 TCP Client Algorithm Issues Connection may not be certain when all information or requests have been transferred Partial close allows graceful termination –shutdown ( s, direction) –0 = no input, 1 = no further output, 2 = both directions –Sends an EOF to Server –When server has completed transmission, it shuts down and then closes socket.

11 CS431-cotter11 TCP Receive Completion Protocol may fragment transmitted packet, but does not directly support any way for the application to determine when the full packet has been received. Therefore, application needs to provide a mechanism to identify when all segments of the packet have been received.

12 CS431-cotter12 Reception Complete Methods Predetermine packet size. Reception is complete when the predetermined number of bytes have been received. –All messages are a fixed size –Each message is of a predetermined size Terminate each packet with a sentinel character Follow each packet with a packet of 0 bytes etc.

13 CS431-cotter13 UDP Client Algorithm Find IP addr and port number of server Allocate a socket Allow UDP to choose an arbitrary, unused local port Specify Server for messages Communicate with server (application level) Close socket

14 CS431-cotter14 UDP Client Algorithm Issues UDP Basic communication Modes –Connected: use aconnect call to specify remote server. then use read/write to communicate –Unconnected: specify server address with each message UDP transfers entire message in a single call. –(assumes buffer space and transport are sufficient) –partial close provides no intersocket communications –UDP is UNRELIABLE! App must be able to deal with inconsistent results.

15 CS431-cotter15 Windows Sockets Introduction History Shared Functions Protocol Specific Functions Socket Database Routines

16 CS431-cotter16 Windows Sockets Winsock 1.1 First formal specification developed in 1992 through an industry task force Winsock 1.1 finalized 1993. Intended to facilitate porting BSD socket code to Windows environment Supports both 16 bit and 32 bit operating environments (Windows 3.0 and up).

17 CS431-cotter17 Windows Sockets Actual implementations are system or machine dependent –All implementations should support winsock.h –Implementation support provided through winsock.dll

18 CS431-cotter18 Windows Sockets Negotiate for appropriate winsock support retvalue = WSAStartup (WORD version, WSADATA SocketImp) –version = The highest version of sockets that the app can use. –SocketImp = data structure containing info on the available socket implementations –retvalue = 0 or error

19 CS431-cotter19 Windows Sockets Close down access to socket implementation retvalue = WSACleanup ( void); –retvalue = 0 or SOCKET_ERROR

20 CS431-cotter20 Windows Sockets Common Socket Routines retval = inet_addr ( dotted ) –dotted = string with IP address in dotted decimal form –retval = unsigned long with IP addr in binary form or INADDR_NONE if not valid retval = inet_ntoa ( ipaddr ) –ipaddr = struct in_addr with IP addr info –retval = string with IP address indotted decimal form

21 CS431-cotter21 Windows Sockets Common Socket Routines htonl ( );htons ( ); ntohl ( );ntohs ( ); socket ( ); bind ( ); connect ( ); select ( ); closesocket ( ); shutdown ( );

22 CS431-cotter22 Windows Sockets Common Socket Routines retvalue = ntohl(netlong); –converts unsigned long from network format to local –(IP Address) retvalue = ntohs(netshort); –converts unsigned short from network format to local –(Port Number) retvalue = htonl(hostlong); –converts unsigned long from local format to network retvalue = htons(hostshort); –converts unsigned short from local format to network

23 CS431-cotter23 Windows Sockets Common Socket Routines retvalue = socket (family, type, protocol); –retvalue = socket descriptor or INVALID_SOCKET (use WSAGetLastError() to retrieve error code) –family = protocol family (PF_INET for IP) –type = (service type: SOCK_STREAM for TCP, SOCK_DGRAM for UDP) –protocol = protocol number or use 0 to match type

24 CS431-cotter24 Windows Sockets Common Socket Routines retvalue = bind (socket, localaddr, addrlen); –retvalue = 0 for success or SOCKET_ERROR –socket = socket to be bound to a port –localaddr = sockaddr struct for local binding address –addrlen = length of localaddr retvalue = connect (socket, addr, addrlen) –retvalue = 0 for success or SOCKET_ERROR –socket = local socket to be used for connection –addr = sockaddr struct for remote binding address –addrlen = length of addr

25 CS431-cotter25 Windows Sockets Common Socket Routines retvalue = select (ignore, refds, wefds, exfds, time); –Will be explained later……. retvalue = closesocket (socket); –retvalue = 0 or SOCKET_ERROR –socket = socket to be closed; retvalue = shutdown ( socket, how); –retvalue = 0 or SOCKET_ERROR; –socket = socket to be shutdown; –how = 0 (incoming), 1 (outgoing), 2 (both directions)

26 CS431-cotter26 Windows Sockets Protocol Specific Functions TCPUDP accept ( );recvfrom( ); listen ( );sendto ( ); recv ( ); send ( );

27 CS431-cotter27 TCP Connection-Oriented Communications retvalue = listen (socket, queuelen); –retvalue = 0 / SOCKETT_ERROR –socket = socket being monitored –queuelen = incoming request queue size retvalue = accept (socket, addr, addrlen); –retvalue = socket descriptor assigned to new connection –socket = incoming socket being monitored –addr = struct sockaddr that is filled in with incoming address information –addrlen = length of address structure

28 CS431-cotter28 TCP Connection-Oriented Communications retvalue = recv (socket, buffer, length, flags); –retvalue = # of bytes received, or 0 if connection is closed, or SOCKET_ERROR if an error occurred –socket = socket used for incoming message –buffer = place where incoming message is stored –length = length of buffer –flags = control type info....

29 CS431-cotter29 TCP Connection-Oriented Communications retvalue = send (socket, msg, msglen, flags); –retvalue = # of bytes sent, or SOCKET_ERROR if an error occurred –socket = socket used for outgoing message –msg = pointer to outgoing message –msglen = length of message –flags = control type info....

30 CS431-cotter30 UDP Connectionless Communications ret = recvfrom (socket, buf, buflen, flags, from, fromlen); SOCKET socket = client socket char FAR* buf = buffer to receive incoming msg intbuflen = size of buffer intflags = control bits (OOB data, etc.) struct sockaddr FAR* from = server address int fromlen = size of address structure

31 CS431-cotter31 UDP Connectionless Communications ret = sendto ( socket, msg, msglen, flags, to, tolen); SOCKET socket = client socket descriptor const char FAR* msg = message for server intmesglen = length of message intflags = control flags (OOB data, etc.) const struct sockaddr FAR* to = server address inttolen = length of address structure

32 CS431-cotter32 Windows Sockets database routines gethostbyaddr ( ); –Returns primary Domain Name for given IP address gethostbyname ( ); –Returns primary IP address for given Domain Name gethostname ( ); –Returns localhost domain name getprotobyname ( ); –Returns protocol number for given protocol name getservbyname ( ); –Returns well-known port number for given well-known port name

33 CS431-cotter33 Summary Foundations for Client / Server Programming Client Side Design Principles Windows Sockets Introduction Windows Sockets Functions


Download ppt "Client Software Design Objectives: Understand principles of C/S design, with focus on clients Review Windows implementations of Socket functions."

Similar presentations


Ads by Google