正在加载图片...
Chapter 4: Server Software Design Multiprotocol Servers Chapter gae Algorithm and issues Motivation for reducing the number of Iterative servers n Concurrent connection-oriented In most cases, a given server handles requests for ne particu servers a Singly-threaded, concurrent particular transport protocol servers The chief advantage of using separate server for a Multiprotocol servers ach protocol lies in contro Multiservice servers The chief disadvantage lies in replication and use Uniform, efficient management of server concurrency Multiprotocol server design A single thread that uses asynchronous I/O Thread Structure for An example multiprotocol multiprotocol Server DAYTIME server A daytime. cpp- main, daytime% Server SOCKE e TCP(const char * int): #define QLEN LINELEN An example multiprotocol An example multiprotocol DAyTIME server DAyTIME server switch(argc)( s main- Iterative server for DAYTIME service service=argv[l] main(int arge, char *argv[D default: ar service ="daytime". service rame or port number xtc"usage: daytime [port]\n") sockaddr in fsin / the request from address % if (wSAStartup(WSVERS, &wsadata)l= O) errexit(WSAStartup failed\n ive TCP(service, QLEN: A isodata _ZERO(&rids10 哈工大计算机学院 李全龙 Network Application Development Server Software Design 55 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 56 Multiprotocol Servers „ Motivation for reducing the number of servers „ In most cases, a given server handles requests for one particular service accessed through one particular transport protocol „ The chief advantage of using separate server for each protocol lies in control „ The chief disadvantage lies in replication and use of resources „ Multiprotocol server design „ A single thread that uses asynchronous I/O 哈工大计算机学院 李全龙 Network Application Development Server Software Design 57 Thread Structure for multiprotocol Server server Server application thread Operating system Socket for UDP requests Socket for TCP conn. requests … Socket for a TCP connection 哈工大计算机学院 李全龙 Network Application Development Server Software Design 58 An example multiprotocol DAYTIME server /* daytimed.cpp - main, daytime */ #include <stdio.h> #include <time.h> #include <winsock.h> void daytime(char buf[]); void errexit(const char *, ...); SOCKET passiveTCP(const char *, int); SOCKET passiveUDP(const char *); #define WSVERS MAKEWORD(2, 0) #define QLEN 5 #define LINELEN 128 哈工大计算机学院 李全龙 Network Application Development Server Software Design 59 An example multiprotocol DAYTIME server /*------------------------------------------------------------------------ * main - Iterative server for DAYTIME service *------------------------------------------------------------------------ */ void main(int argc, char *argv[]) { char *service = "daytime"; /* service name or port number */ char buf[LINELEN+1]; /* buffer for one line of text */ struct sockaddr_in fsin;/* the request from address */ int alen; /* from-address length */ SOCKET tsock; /* TCP master socket */ SOCKET usock; /* UDP socket */ fd_set rfds; /* readable file descriptors */ int rv; WSADATA wsadata; 哈工大计算机学院 李全龙 Network Application Development Server Software Design 60 An example multiprotocol DAYTIME server switch (argc) { case 1: break; case 2: service = argv[1]; break; default: errexit("usage: daytimed [port]\n"); } if (WSAStartup(WSVERS, &wsadata) != 0) errexit("WSAStartup failed\n"); tsock = passiveTCP(service, QLEN); usock = passiveUDP(service); FD_ZERO(&rfds);
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有