1 / 33

Client Software Design

Client Software Design. Objectives: Understand principles of C/S design, with focus on clients Review Windows implementations of Socket functions. Architectural Objectives for C/S. Partition applications across multiple machines better utilization of computing resources

dixie
Télécharger la présentation

Client Software Design

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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. C/S Architecture Application Server Client

  4. 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. 2-Tier vs. 3-Tier C/S Design • 3-Tier design extends distribution of application across more levels / platforms. • Client Local Server Enterprise Server Local Database Enterprise Database App. Server Database Server

  6. 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. 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. 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. 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. 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. 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. 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. 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. 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. Windows Sockets Introduction • History • Shared Functions • Protocol Specific Functions • Socket Database Routines

  16. Windows SocketsWinsock 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. Windows Sockets • Actual implementations are system or machine dependent • All implementations should support winsock.h • Implementation support provided through winsock.dll

  18. 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. Windows Sockets • Close down access to socket implementation • retvalue = WSACleanup ( void); • retvalue = 0 or SOCKET_ERROR

  20. Windows SocketsCommon 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. Windows SocketsCommon Socket Routines • htonl ( ); htons ( ); • ntohl ( ); ntohs ( ); • socket ( ); • bind ( ); • connect ( ); • select ( ); • closesocket ( ); • shutdown ( );

  22. Windows SocketsCommon 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. Windows SocketsCommon 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. Windows SocketsCommon 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. Windows SocketsCommon 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. Windows Sockets Protocol Specific Functions TCPUDP accept ( ); recvfrom( ); listen ( ); sendto ( ); recv ( ); send ( );

  27. TCP Connection-OrientedCommunications • 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. TCP Connection-OrientedCommunications • 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. TCP Connection-OrientedCommunications • 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. UDP Connectionless Communications • ret = recvfrom (socket, buf, buflen, flags, from, fromlen); SOCKET socket = client socket char FAR* buf = buffer to receive incoming msg int buflen = size of buffer int flags = control bits (OOB data, etc.) struct sockaddr FAR* from = server address int fromlen = size of address structure

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

  32. Windows Socketsdatabase 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. Summary • Foundations for Client / Server Programming • Client Side Design Principles • Windows Sockets Introduction • Windows Sockets Functions

More Related