Download presentation
Presentation is loading. Please wait.
Published bySophia Conley Modified over 8 years ago
1
1 Server Design Discuss Design issues for Servers Review Server Creation in Windows
2
2 Server Software Design Concurrent Vs. Iterative –Concurrent servers support multiple clients concurrently (may or may not use concurrent processes) –Iterative servers support a single client at a time. (Much easier to build, but usually much less efficient)
3
3 Server Software Design Concurrent Vs. Iterative –Concurrent servers support multiple clients concurrently (may or may not use concurrent processes) –Iterative servers support a single client at a time. (Much easier to build, but usually much less efficient) Connection-Oriented Vs. Connectionless –Connection Oriented access is provided through TCP which provides all of the reliability for the access. –Connectionless access is provided through UDP, and requires the application to provide reliability.
4
4 Server Software Design Stateless Vs. Stateful Servers –Stateful servers maintain status of ongoing client communications. Use of state information can allow more efficient communication (less information needed in each message), but it does open up the possibility of state dependencies if not carefully designed into the server. –Stateless servers rely on the client to provide all of the information needed for each request. Easier to design, but generally less efficient.
5
5 Stateless Vs. Stateful Servers Example Client queries server for file information (ftp, database search, etc.) Stateless model: –query includes filename, offset, # of bytes to read
6
6 Stateless Vs. Stateful Servers Example Client queries server for file information (ftp, database search, etc.) Stateless model: –query includes filename, offset, # of bytes to read Stateful model: –server maintains table of client info current queries containing filename, current offset –client sends request to read # of bytes –server accesses buffer for info, if available,or disk file.
7
7 Stateless Vs. Stateful Servers Filename: X Offset: 512 Buffer Pointer: Filename: Y Offset: 1024 Buffer Pointer: hash(IP, port) Buffer for file X, pointer at 512 Buffer for file Y, pointer at 1024
8
8 Basic Server Types Iterative connectionless Iterative connection-oriented Concurrent connectionless Concurrent connection-oriented
9
9 Basic Server Types Iterative connectionless Iterative connection-oriented Concurrent connectionless Concurrent connection-oriented
10
10 Iterative Connection-Oriented Server Create a socket & bind to the port for the service being offered. Place the socket in passive mode (listen) Accept the next connection request from the socket and obtain a new socket for the connection. Repeatedly send a request from client, formulate a response, and send response back to client. When finished with a client, close the connection & return to accept mode, waiting for a new connection.
11
11 Iterative Connectionless Server Create a socket and bind to the well- known address for the service being offered. Repeatedly read the next request from a client, formulate a response, and send a reply back to the client according to the application protocol.
12
12 Concurrent Connectionless Server (P) Create a socket & bind to the port for the service being offered. (P) Repeatedly call recvfrom to receive the next request from client, & create a new child process (c) Recieve a specific request upon creation as well as access to the socket. (c) Form a reply according to application protocol and send it back to client using sendto. (c) Terminate child process upon completion of task
13
13 Concurrent Connection- Oriented Server (P) Create a socket & bind to the port for the service offered. Leave the socket unconnected (P) Place the socket in passive mode (listen) (P) Repeatedly call accept to receive the next request from client, & create new child process (c) Receive a connection request upon creation (c) Interact with client (read request(s) & send(s)) (c) Terminate child process upon completion of task
14
14 Server Issues Request processing time Vs. Observed response time
15
15 Server Issues Request processing time Vs. Observed response time Use of INADDR_ANY to receive datagrams from any IP address.
16
16 Server Issues Request processing time Vs. Observed response time Use of INADDR_ANY to receive datagrams from any IP address. Connectionless communications: –ans = sendto(s, buf, buflen, flags, toaddr, toaddrlen) –ans = recvfrom(s, buf, buflen, flags, toaddr, toaddrlen)
17
17 Server Issues Request processing time Vs. Observed response time Use of INADDR_ANY to receive datagrams from any IP address. Connectionless communications: –ans = sendto(s, buf, buflen, flags, toaddr, toaddrlen) –ans = recvfrom(s, buf, buflen, flags, toaddr, toaddrlen) Use of exec for child processes
18
18 Apparent vs Real Concurrency Create a socket and bind to the well-known address for the service being offered. Add socket to the list of those on which I/O is possible
19
19 Apparent vs Real Concurrency Create a socket and bind to the well-known address for the service being offered. Add socket to the list of those on which I/O is possible Use select to wait for I/O on existing sockets
20
20 Apparent vs Real Concurrency Create a socket and bind to the well-known address for the service being offered. Add socket to the list of those on which I/O is possible Use select to wait for I/O on existing sockets If original responds, use accept for new connection & add socket to the list If other socket responds, use read / write to communicate Return to select
21
21 Apparent Concurrency Select (fdsize, &fd_set_in, &fd_set_out, &fd_set_err, time) –Fdsize: Not used in Windows, but used in UNIX or Linux to indicate the number of sockets that should be scanned. –&fd_set_in:address of the file descriptor set that is monitoring sockets for pending input work –&fd_set_out: Address of the file descriptor set that is moniroting sockets for pending outgoing work. –&fd_set_err: File descriptor set that monitors for exceptions to normal work (special error messages, or urgent messages) –Time: set to NULL to wait until there is some activity. Otherwise may be set to the maximum time to wait until select function returns.
22
22 Server Creation in Windows Formal service creation and installation requires administrative privilege.
23
23 Server Creation in Windows Formal service creation and installation requires administrative privilege. Normal console applications maintain access to a console window. Can’t delete window without terminating process.
24
24 Server Creation in Windows Formal service creation and installation requires administrative privilege. Normal console applications maintain access to a console window. Can’t delete window without terminating process. Would like to create a new process that is detached from the console (runs in “background” mode.
25
25 CreateProcess BOOL CreateProcess ( LPCTSTR IpApplicationName, LPTSTRIpCommandLine, LPSECURITY_ATTRIBUTES IpProcessAttributes, LPSECURITY_ATTRIBUTES IpthreadAttributes, DWORD fdwCreate, BOOLbInheritHandles, LPVOIDIpEnvironment, LPCTSTRIpCurrentDirectory, LPSTARTINFO IpStartInfo, LPPROCESS_INFORMATION IpProcessInformation );
26
26 struct STARTUPINFO typedef struct _STARTUPINFO { DWORDcb;DWORDdwFillAttribute; LPSTRlpReserved;DWORDdwFlags; LPSTR lpDesktop;WORDwShowWindow; LPSTRlpTitle;WORDcbReserved2; DWORDdwX;LPBYTE lpReserved2; DWORDdwY;HANDLE hStdInput; DWORDdwXSize;HANDLE hStdOutput; DWORDdwYSize;HANDLE hStdError; DWORDdwXCountChars; DWORDdwYCountChars; } STARTUPINFO, *LPSTARTUPINFO;
27
27 struct PROCESS_INFORMATION typedef struct _PROCESS_INFORMATION HANDLEhProcess; HANDLEhThread; DWORDdwProcessId; DWORDdwThreadID; } PROCESS_INFORMATION, *LPPROCESS_INFORMATION;
28
28 Server Creation in Windows WinProcess.cpp #include #define NAMESIZE 50 void main (int argc, char *argv[]) { char AppName[NAMESIZE] = "timetest.exe"; char answer[NAMESIZE]; STARTUPINFO si; PROCESS_INFORMATION ProcessInformation;
29
29 Server Creation in Windows WinProcess.cpp // Get the desired background process name... if (argc != 2) { printf("Usage: Winprocess background_prog\n"); exit(1); } strcpy(AppName, argv[1]); printf("Starting %s in background mode. OK?(yes/no) ", AppName); gets (answer); if (strcmp(answer, "yes") != 0) { printf("Aborting background program startup...\n"); printf("Select any key to continue....."); gets(answer); exit(1); }
30
30 Server Creation in Windows WinProcess.cpp // Initialize the STARTINFO buffer to the // parameters needed for a detached process si.cb = sizeof(STARTUPINFO); si.lpReserved = NULL; si.lpTitle = NULL; si.lpDesktop = ""; si.dwX = 0L; si.dwY = 0L; si.dwXSize = 0L; si.dwYSize = 0L; si.dwFlags = 0; si.wShowWindow = SW_SHOW; si.lpReserved2 = NULL; si.cbReserved2 = 0;
31
31 Server Creation in Windows WinProcess.cpp if (!CreateProcess(NULL, AppName, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &si, &ProcessInformation)) { printf("ERROR: Cannot launch child process\n"); printf("Select any key to continue....."); gets(answer); exit(1); } printf("New process id: %ld, new thread id: %ld\n", ProcessInformation.dwProcessId, ProcessInformation.dwThreadId); printf("Select any key to close WinProcess..."); gets(answer); }
32
32 timetest.cpp #include #define MYBUFFER80 #define ENTRYCOUNT15 void main () { char *timeptr; intentries; FILE *fp; time_t newtime;
33
33 timetest.cpp if ((fp = fopen( "timetest.dat", "w" )) == NULL ) exit(1); fputs( "This is my time test file.\n\n", fp); fclose (fp); for (entries = 0; entries < ENTRYCOUNT; entries++) { (void) time (&newtime); timeptr = ctime(&newtime); if ((fp = fopen( "timetest.dat", "a" )) == NULL ) exit(1); fputs (timeptr, fp); fputs ("Now we sleep... \n\n\n", fp); fclose (fp); Sleep (1000L); }
34
34 timetest.cpp (output) C:\cotter\cs490d_ws98\WinProcess>winprocess timetest This will start timetest in background mode. Proceed?(yes/no) yes The new process id is 68, and the new thread id is 46 Select any key to close WinProcess... C:\cotter\cs490d_ws98\WinProcess>
35
35 Summary Several different factors involved in server design 4 basic types of servers Server concurrency can be real or apparent Server creation in Windows allows user to configure operating environment for the server program
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.