正在加载图片...
Closing connections Chapter 4: Server Software Design Calling closesocket requests a graceful Algorithm and issues Does not worry about data lost Iterative servers s Concurrent connection-oriented The application protocol determines how a server manages TCP connections a Singly-threaded, concurrent The client must signal completion a Allowing a client to control connection Multiprotocol servers duration can be dangerous Multiservice servers Uniform, efficient management of server concurrency Concurrent Connection-oriented Thread Structure for Concurrent Servers Connection-oriented server Consider concurrent ECHO Iterative VS Concurrent implementation application thread Concurrent avoids long delay Concurrent offers better observed response time An example concurrent ECHO server An example concurrent ECHO server TCPechod cpp-main, TOPechod*/ main-Concurrent TCP server for ECHO service #define QLEN 5/ maximum connection queue length * i shrue erice soch di n sin he adres renumber "y STKSIZE FSIZE #define WSVERS switch(arge)( SOCKET sock, sock: / master slave TCPechod(SOCKET) service= argil] errexit(const char *,.: SoCKET passive TCP(const char * int) errexit("usage: TCPechod [port]\m")7 哈工大计算机学院 李全龙 Network Application Development Server Software Design 37 Closing connections „ Calling closesocket requests a graceful shutdown „ Does not worry about data lost „ The application protocol determines how a server manages TCP connections „ The client must signal completion „ Allowing a client to control connection duration can be dangerous 哈工大计算机学院 李全龙 Network Application Development Server Software Design 38 Chapter 4: Server Software Design Chapter goal: „ Algorithm and issues „ Iterative servers „ Concurrent, connection-oriented servers „ Singly-threaded, concurrent servers „ Multiprotocol servers „ Multiservice servers „ Uniform, efficient management of server concurrency 哈工大计算机学院 李全龙 Network Application Development Server Software Design 39 Concurrent Connection-oriented Servers „ Consider concurrent ECHO „ Iterative VS Concurrent implementation „ Iterative performs poorly „ Concurrent avoids long delay „ Concurrent offers better observed response time 哈工大计算机学院 李全龙 Network Application Development Server Software Design 40 Thread Structure for Concurrent Connection-oriented Server server Server application thread Operating system Socket for Connection requests Socket for individual connection slave1 slave2 slaven … 哈工大计算机学院 李全龙 Network Application Development Server Software Design 41 An example concurrent ECHO server /* TCPechod.cpp - main, TCPechod */ #include <stdio.h> #include <winsock.h> #include <process.h> #define QLEN 5 /* maximum connection queue length */ #define STKSIZE 16536 #define BUFSIZE 4096 #define WSVERS MAKEWORD(2, 0) SOCKET msock, ssock; /* master & slave server sockets */ int TCPechod(SOCKET); void errexit(const char *, ...); SOCKET passiveTCP(const char *, int); 哈工大计算机学院 李全龙 Network Application Development Server Software Design 42 An example concurrent ECHO server /*------------------------------------------------------------------------ * main - Concurrent TCP server for ECHO service *------------------------------------------------------------------------ */ int main(int argc, char *argv[]) { char *service = "echo"; /* service name or port number */ struct sockaddr_in fsin; /* the address of a client */ int alen; /* length of client's address */ WSADATA wsadata; switch (argc) { case 1: break; case 2: service = argv[1]; break; default: errexit("usage: TCPechod [port]\n"); }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有