香港浸会大学:《Data Communications and Networking》课程教学资源(PPT讲稿)Socket Programming Part II:Design of Server Software

Data communications and Networking Socket Programming Part I: Design of Server Software Reference Internetworking with TCP/p volume Client-Server Programming and Applications By Douglas E, Comer David L, Stevens
1 Data Communications and Networking Socket Programming Part II: Design of Server Software Reference: Internetworking with TCP/IP, Volume III Client-Server Programming and Applications By Douglas E. Comer, David L. Stevens

Outline Review of multithreading Server design -Iterative Connectionless -Iterative. Connection-Oriented Concurrent. Connectionless -Concurrent Connection-Oriented Multi-thread Singly threaded (not required by CoMP2330)
2 Outline • Review of multithreading • Server Design —Iterative, Connectionless —Iterative, Connection-Oriented —Concurrent, Connectionless —Concurrent, Connection-Oriented • Multi-thread • Singly threaded (not required by COMP2330)

Multithreading In modern operating systems, a process can have multiple threads They share the process's resources such as memory space, opened files. sockets. etc Advantages -Good for cPUs with multiple cores - -Can overlap different Io. E.g., a thread can wait for an input from the user, while another thread is receiving data from the network -Context switching between threads is faster than that between processes
3 Multithreading • In modern operating systems, a process can have multiple threads —They share the process’s resources such as memory space, opened files, sockets, etc. • Advantages —Good for CPUs with multiple cores —Can overlap different IO. E.g., a thread can wait for an input from the user, while another thread is receiving data from the network —Context switching between threads is faster than that between processes

Threads in ms windows a thread is executed independently of other threads All threads in a process share -Global variables -Resources that the os allocates to the process When multiple threads execute a piece of code concurrent -Each thread has its own, independent copy of the local variables associated with the code -Each has its own run-time stack of procedure activation records
4 Threads in MS Windows • A thread is executed independently of other threads. • All threads in a process share: —Global variables —Resources that the OS allocates to the process • When multiple threads execute a piece of code concurrently —Each thread has its own, independent copy of the local variables associated with the code. —Each has its own run-time stack of procedure activation records

Threads in MS Windows(Cont) A program can call beginthreado to create a new thread to execute a specified function. Then the program and the newly created thread are executed concurrently unsigned long beginthread( void(* Func )(void *), unsigned stack size, void arglist) The lst parameter: start address of the function to be executed The 2nd parameter: stack size for the new thread: 0 for system default The 3rd parameter: pointer to a list of parameters to be passed to the function NULL for no parameter Two remarks: must be included 2. The application must link with one of the multithreaded C run-time libraries E using the "/MT option of cl. exe command 5
5 Threads in MS Windows (Cont.) • A program can call _beginthread() to create a new thread to execute a specified function. Then the program and the newly created thread are executed concurrently. unsigned long _beginthread( void(* Func )(void *), unsigned stack_size, void *arglist ); The 1st parameter: start address of the function to be executed The 2nd parameter: stack size for the new thread; 0 for system default The 3rd parameter: pointer to a list of parameters to be passed to the function; NULL for no parameter Two remarks: 1. must be included 2. The application must link with one of the multithreaded C run-time libraries. E.g., using the “/MT” option of cl.exe command

Threads in MS Windows(Cont / threadsum c * int addem(int count) /* To compile: >cl threadsum.c /MT*/ nt 1. sum #include for(i=1; i<=count; 1++) int addem (int) printf(" The value of i is %d\n,1); Int main( fflush(stdout) beginthread((void ()(void)addem, 0, (void *)5); sum +=1 addem(5); return 0 printf("The sum of i is %d n', sum) fflush(stdout) return 0 6
6 Threads in MS Windows (Cont.) int addem(int count) { int i, sum; sum = 0; for(i = 1; i cl threadsum.c /MT */ #include #include #include int addem(int); int main() { _beginthread( (void (*)(void())addem, 0, (void *)5); addem(5); return 0; }

Threads in Ms Windows(Cont y ca Visual Studio. NET 2003 Command Prompt □ D: \hkbu\teaching \comp2330\2009>cl threadsum.c /MT Copyright (C) Microsoft Corporation 1984-2002. All rights reserved or80x86 Microsoft (R)32-bit C/C++ Optimizing Compiler Version 13.10.6030 f Microsoft (R> Incremental Linker Version 7.10.6030 opyright (c) Microsoft Corporation. All rights reserved out: threadsum exe threads. obj D: \ hkbu \teaching \comp2330\ 2009>threadsum D: \hkbu \teaching\comp2330\2009>threadsum The value of i is 1 he value of i is 1 The value of i is 1 The value of i The value of i is 2 he value of i is/2 The value of i i The value of i is 3 f lue of i is 2 he value of i is 3 The value of i is3 The value of i is 4 The value of i is 4 The value of i is 5 The value of The value of i is 5 The sum is 15 The value of i is 5 is 15 The sum is 15 The sum is 15 D: \hkbu \teaching \comp2330\2009> D: \hkbu \teaching \comp2330\2009>
7 Threads in MS Windows (Cont.)

Server Design Issues Connectionless vs. connection-oriented - UDP vS TCP -Reliability issue? tCP wins - Support of broadcast or multicast? UDP wins -Real time applications? UDP may win Client and server must use the same protocol
8 Server Design Issues • Connectionless vs. connection-oriented —UDP vs. TCP —Reliability issue? TCP wins. —Support of broadcast or multicast? UDP wins. —Real time applications? UDP may win. • Client and server must use the same protocol

Server Design Issues(Cont) Iterative vs. concurrent -Iterative server handles one request at a time -If another request arrives while the server is busy handling an existing request, the new request has to wait Iterative servers are easier to design, implement and maintain Iterative server is not good for a service with a long request processing time -Concurrent server handles multiple requests concurrently It can decrease the response time It can achieve high performance on a server with multiple processors It can achieve high performance by overlapping processing and IO 9
9 Server Design Issues (Cont.) • Iterative vs. concurrent —Iterative server handles one request at a time. —If another request arrives while the server is busy handling an existing request, the new request has to wait. • Iterative servers are easier to design, implement, and maintain. • Iterative server is not good for a service with a long “request processing time”. —Concurrent server handles multiple requests concurrently. • It can decrease the response time. • It can achieve high performance on a server with multiple processors. • It can achieve high performance by overlapping processing and I/O

terative server server client being served waiting clients 10
10 Iterative Server server client being served waiting clients
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 中国科学技术大学:《网络算法学》课程教学资源(PPT课件)第六章 传输控制.ppt
- 西安电子科技大学:《MATLAB程序设计语言》课程教学资源(PPT讲稿)Chapter1 Matlab系统概述.ppt
- 清华大学:Mandarin Pronunciation Variation Modeling.ppt
- 清华大学出版社:《C语言程序设计》课程教学资源(PPT课件讲稿)第7章 用户自定义函数.ppt
- 中国科学技术大学:《算法基础》课程教学资源(PPT课件讲稿)第七讲 顺序统计学(主讲人:吕敏).pptx
- 《Java语言程序设计》课程教学资源(PPT课件讲稿)第三章 面向对象特征.ppt
- Virtual Topologies - Faculty of Science, HKBU.ppt
- 《Adobe Photoshop CS》软件教程(PPT讲稿)第13章 使用路径.ppt
- 《软件开发》课程PPT教学课件:Chapter 16 异常处理 Exception Handling.ppt
- 西安电子科技大学:《计算机网络 Computer Networks》课程教学资源(PPT课件讲稿)基于CORBA的分布式平台(CORBA编程-Hello World例程).ppt
- 电子工业出版社:《计算机网络》课程教学资源(第五版,PPT课件讲稿)第七章 网络安全.ppt
- 北京大学:浅谈计算机研究的层次与境界(李振华).pptx
- 南京大学:《计算机图形学》课程教学资源(PPT课件讲稿)计算机图形学引言(主讲:路通).ppt
- 国家十一五规划教材:《电子商务案例分析》课程教学资源(PPT课件)第11章 网络社区模式案例分析.ppt
- 西安电子科技大学:《操作系统 Operating Systems》课程教学资源(PPT课件讲稿)Chapter 08 多处理器系统 Multiple Processor Systems.ppt
- 计算机问题求解(PPT讲稿)图论中的其它专题.pptx
- SIGCOMM 2002:New Directions in Traffic Measurement and Accounting.ppt
- 厦门大学计算机科学系:《大数据技术原理与应用》课程教学资源(PPT课件)第十章 数据可视化.ppt
- 成都信息工程大学(成都信息工程学院):分层分流培养个性发展的计算机卓越工程师——专业课分层教学探索与实践.ppt
- 沈阳理工大学:《Java程序设计基础》课程教学资源(PPT课件讲稿)第1章 创建Java开发环境.ppt
- 上海交通大学:《软件开发》课程教学资源(PPT课件)第一讲 概述.ppt
- 《计算机网络原理》课程教学资源(PPT课件讲稿)第二章 网络实现模型.ppt
- 香港理工大学:INSTRUCTION SETS 指令.pptx
- 计算机问题求解(PPT讲稿)B树.pptx
- 北京大学远程教育:《计算机应用基础》课程PPT教学课件(专科)串讲(综合复习).pptx
- 《Microsoft Access 2003》教程PPT:第9章 报表设计.ppt
- 《编译原理和技术》课程PPT教学课件:第十三章 函数式语言的编译.ppt
- 四川大学:Object-Oriented Design and Programming(Java,PPT课件).ppt
- 安徽理工大学:《汇编语言》课程教学资源(PPT课件讲稿)第五章 循环与分支程序设计.ppt
- 《C程序设计》课程PPT教学课件(电子教案)第六章 函数.ppt
- 基于语义关联和信息增益的TFIDF改进算法研究.ppt
- Integrated analysis of regulatoryand metabolic networks revealsnovel regulatory mechanisms inSaccharomyces cerevisiae.ppt
- 山东大学:《计算机图形学》课程PPT教学课件(Programming with OpenGL)Part 3:Three Dimensions.ppt
- 《算法设计技巧与分析》课程教学资源(PPT讲稿)Lecture 8 贪婪法则 Greedy Approach.ppt
- 山西国际商务职业学院:《网页设计与制作》课程教学资源(PPT课件)第一章 网页设计基础知识.ppt
- 《多媒体教学软件设计》课程PPT教学课件:第13章 多媒体教学软件中脚本编程技巧.ppt
- 中国科学技术大学:《计算机体系结构》课程教学资源(PPT课件讲稿)动态调度(Cont)、推断执行和ILP.ppt
- 香港浸会大学:《Experiencing Cluster Computing》Class 8 Case Studies.ppt
- 香港理工大学:Building Robust Wireless LAN for Industrial Control with DSSS-CDMA Cell Phone Network Paradigm.ppt
- International Trade Forms.ppt