《Indy In Depth》中文版

来源:互联网 发布:淘宝店铺粉丝最多 编辑:程序博客网 时间:2024/06/05 23:43

《Indy In Depth》中文版,Delphi 网络通信入门

Indy是Delphi用来进行网络通信的常用控件。无奈教程太少,网上零零散散的一些。

《Indy In Depth》是Indy控件的官方入门教程,但之前网上只有英文版的。

本人一咬牙,花了好几个月的业余时间翻译成了中文版,水平有限,难免会有一些错误或者疏漏的地方,敬请联系我指出。

其实在发文章前早已发到资源里去了,今天开通了博客,就先发这个出来试试水。大笑


翻译完后发现,这本教程不只是一本教你如何使用Indy控件的教程,里头包含了网络通信的基础知识:TCP,UDP,网络协议,端口等等,还有Delphi的多线程入门知识等,很适合新手学习,即使不用Indy控件,也值得一看。

这里是下载地址,翻译的这么累稍微收个3分辛苦费,请不要另行分发,实在没有分又急着要的可以直接加我QQ索取,QQ在下面的图片中。


最后附上目录

目录
Indy In Depth ...................................................................... 1
3 Socket介绍 ................................................................... 12
3.1 综述 .................................................................................................................... 12
3.2 TCP/IP................................................................................................................... 12
3.3 Client 客户端 ....................................................................................................... 12
3.4Server 服务器 ....................................................................................................... 12
3.5 IP地址 ................................................................................................................. 12
3.6 Port 端口 ............................................................................................................. 13
3.7 Protocol协议........................................................................................................ 13
3.8 Socket 接口 ......................................................................................................... 13
3.9 Host Name主机名 ................................................................................................ 13
3.10 DNS .................................................................................................................... 14
3.11 TCP ..................................................................................................................... 14
3.12 UDP .................................................................................................................... 14
3.13 ICMP................................................................................................................... 15
3.14 HOSTS................................................................................................................. 15
3.15 SERVICES............................................................................................................. 15
3.16 Localhost(Loopback 本地环回接口) 本地主机 ................................................... 16
3.17 Ping .................................................................................................................... 16
3.18 TraceRoute 路由跟踪 ......................................................................................... 17
3.19 LAN 局域网........................................................................................................ 18
3.20 WAN 广域网 ...................................................................................................... 18
3.21 IETF .................................................................................................................... 18
3.22 RFC ..................................................................................................................... 18
3.23 Thread 线程 ....................................................................................................... 18
3.24 Fork .................................................................................................................... 19
3.25 Winsock .............................................................................................................. 19
3.26 Stack 栈 ............................................................................................................. 19
3.27 Network Byte Order ............................................................................................ 19
4 Indy介绍....................................................................... 20
4.1 Then Indy Way ...................................................................................................... 20
4.2 Indy Methodology................................................................................................. 20
4.3 How Indy is Different Indy的独特之处 ............................................................... 20
4.4 客户端概述 ......................................................................................................... 21
4.5 服务器概述 ......................................................................................................... 21
4.6 Threading ............................................................................................................. 21
5 Blocking vs. Non-Blocking 阻塞和非阻塞 ........................ 22
5.1 Programming Models 编程模型 ........................................................................... 22
5.2 其他模型 ............................................................................................................. 22
5.3 阻塞 .................................................................................................................... 22
5.4 非阻塞................................................................................................................. 22
5.5 Winsock 的历史 ................................................................................................... 22
5.6 Blocking is not Evil 阻塞并不烂 ............................................................................ 23
5.7 Pros of Blocking 阻塞的优点 ................................................................................ 23
5.8 Cons of Blocking 阻塞的缺点............................................................................. 23
5.9 TIdAntiFreeze........................................................................................................ 24
5.10 Pros of Non-Blocking 非阻塞的优点 ................................................................... 24
5.11 Cons of Non-Blocking 非阻塞的缺点 .................................................................. 24
5.12 Comparison 对比 ............................................................................................... 24
5.13 Files vs. Sockets................................................................................................... 25
5.14 Scenario.............................................................................................................. 25
5.15 Blocking File Write 写阻塞文件 .......................................................................... 26
5.16 Non-Blocking File Write 写非阻塞文件 ............................................................... 26
5.17 File Write Comparison 写文件对比..................................................................... 27
5.18 Just Like Files ...................................................................................................... 27
6 客户端介绍 .................................................................. 28
6.2 Handling Exceptions 异常处理 ............................................................................. 28
6.3 Exceptions are not Errors 异常并非错误............................................................... 29
6.4 TIdAntiFreeze (VCL中有,FMX中没有) .......................................................... 29
6.5 Demo - Postal Code Client 示例—邮编客户端 ...................................................... 30
6.5.1 Postal Code Protocol 邮编协议 ...................................................................................................... 30
6.5.2 Code Explanation ................................................................................................................................ 31
7 UDP............................................................................... 33
7.1 Overview 综述 ..................................................................................................... 33
7.2 Reliability可靠性 ................................................................................................. 33
7.3 Broadcasts 广播 ................................................................................................... 33
7.4 Packet Sizes 数据包大小 ...................................................................................... 34
7.5 Confirmations ....................................................................................................... 34
7.5.1 Overview 综述 ................................................................................................................................... 34
7.5.2 Acknowledgements ............................................................................................................................ 34
7.5.3 Sequencing 排序 ............................................................................................................................... 34
7.6 TIdUDPClient ........................................................................................................ 35
7.7 TIdUDPServer ....................................................................................................... 35
7.8 UDP Example - RBSOD........................................................................................... 35
7.8.1 Overview .............................................................................................................................................. 35
7.8.2 Server.................................................................................................................................................... 37
7.8.3 Client 客户端 ..................................................................................................................................... 38
8 Reading and Writing 读写....................................................................................... 40
8.1 Read Methods 读的方法 ...................................................................................... 40
8.1.1 AllData .................................................................................................................................................. 41
8.1.2 Capture ................................................................................................................................................. 41
8.1.3 CurrentReadBuffer ............................................................................................................................. 41
8.1.4 InputBuffer........................................................................................................................................... 41
8.1.5 InputLn ................................................................................................................................................. 41
8.1.6 ReadBuffer ........................................................................................................................................... 42
8.1.7 ReadCardinal ....................................................................................................................................... 42
8.1.8 ReadFromStack ................................................................................................................................... 42
8.1.9 ReadInteger ......................................................................................................................................... 42
8.1.10 ReadLn ................................................................................................................................................ 42
8.1.11 ReadLnWait ....................................................................................................................................... 42
8.1.12 ReadSmallInt ..................................................................................................................................... 42
8.1.13 ReadStream ....................................................................................................................................... 43
8.1.14 ReadString.......................................................................................................................................... 43
8.1.15 ReadStrings........................................................................................................................................ 43
8.1.16 WaitFor............................................................................................................................................... 43
8.2 Read Timeouts 读取时限........................................................................................................................ 43
8.3 Write Methods 写方法............................................................................................................................. 44
8.3.1 SendCmd .............................................................................................................................................. 45
8.3.2 Write ..................................................................................................................................................... 45
8.3.3 WriteBuffer .......................................................................................................................................... 45
8.3.4 WriteCardinal ...................................................................................................................................... 45
8.3.5 WriteHeader ........................................................................................................................................ 45
8.3.6 WriteInteger ........................................................................................................................................ 45
8.3.7 WriteLn ................................................................................................................................................. 45
8.3.8 WriteRFCReply..................................................................................................................................... 46
8.3.9 WriteRFCStrings .................................................................................................................................. 46
8.3.10 WriteSmallInt .................................................................................................................................... 46
8.3.11 WriteStream ...................................................................................................................................... 46
8.3.12 WriteStrings....................................................................................................................................... 46
8.3.13 WriteFile............................................................................................................................................. 46
8.4 Write Buffering 写缓存 ........................................................................................ 47
8.5 Work Transactions 工作事件 ................................................................................ 47
8.5.1 OnWork Events.................................................................................................................................... 47
8.5.2 Managing Your Own Work Transactions......................................................................................... 48
管理自己的工作事务 ................................................................................................................................. 48
9 Detecting Disconnects 探测断链 ............................................................................................................. 49
9.1 Saying Good Bye 说再见 ...................................................................................... 49
9.2 Do you really need to know? 你真需要知道吗 .............................................................................. 49
9.3 I need to know now! 我要立刻知道 ..................................................................... 49
9.3.1 Keep Alives........................................................................................................................................... 50
9.3.2 Pings ...................................................................................................................................................... 50
9.4 EIdConnClosedGracefully....................................................................................... 50
9.4.1 Introduction 介绍.............................................................................................................................. 50
9.4.2 Why Does This Exception Occur in Servers? .................................................................................. 51
9.4.3 Why is it an Exception? 为什么这是个异常? ........................................................................... 51
9.4.4 Is it an Error? 这是个错误吗? ...................................................................................................... 51
9.4.5 When is it an Error? 什么时候它是个错误 ............................................................................... 52
9.4.6 Simple Solution 简单处理 ............................................................................................................... 52
10 Implementing Protocols 实现协议 ................................................................................................ 53
10.1 Protocol Terminology 协议专有名词 ......................................................................................... 53
10.1.1 Plain Text 纯文本 ............................................................................................................................ 54
10.1.2 Command 命令 ............................................................................................................................... 54
10.1.3 Reply 答复 ........................................................................................................................................ 54
10.1.4 Response 答复................................................................................................................................. 54
10.1.5 Conversations 会话......................................................................................................................... 55
10.2 RFC Definitions................................................................................................................................... 55
10.2.1 RFC Status Codes RFC状态码 ....................................................................................................... 56
10.2.2 RFC Reply ........................................................................................................................................... 57
10.2.3 RFC Response .................................................................................................................................... 57
10.2.4 RFC Transactions RFC事件 ............................................................................................................. 57
10.3 TIdReplyRFC(原文中是TIdRFCReply,XE10中改为这) ........................................... 57
10.4 ReplyTexts........................................................................................................... 58
10.5 The Chicken or the Egg?....................................................................................... 58
10.6 Defining a Custom Protocol 定义个定制协议...................................................... 59
10.7 Peer Simulation................................................................................................... 59
10.8 Postal Code Protocol ........................................................................................... 60
10.8.1 Help 帮助.......................................................................................................................................... 60
10.8.2 Lookup 查询..................................................................................................................................... 61
10.8.3 Quit 退出 .......................................................................................................................................... 62
11 Proxies 代理.............................................................................................................. 63
11.1 Transparent Proxies 透明代理 ............................................................................ 63
11.1.1 IP Masquerading / Network Address Translation (NAT) IP伪装/网络地址转换 ......... 63
11.1.2 Mapped Ports / Tunnels 映射端口/隧道 ................................................................................... 63
11.1.3 FTP User@Site Proxy........................................................................................................................ 64
11.2 Non Transparent Proxies 非透明代理 ................................................................. 64
11.2.1 SOCKS 防火墙安全会话转换协议 .............................................................................................. 64
11.2.2 HTTP (CERN) ...................................................................................................................................... 65
12 IOHandlers ................................................................... 66
12.1 IOHandler Components IOHandler组件 ........................................................... 66
12.1.1 TIdIOHandlerSocket ......................................................................................................................... 67
12.1.2 TIdIOHandlerStream ........................................................................................................................ 67
12.1.3 TIdSSLIOHandlerSocket(TIdSSLIOHandlerSocketOpenSSL) ....................................................... 67
12.2 Demo - Speed Debugger 例子-速度调试器 ....................................................... 67
12.2.1 Custom IOHandler 定制IOHandler(并没有Recv方法).......................................................... 68
13 Intercepts .............................................................................................................. 69
13.1 Intercepts ........................................................................................................... 69
13.2 Logging ............................................................................................................... 69
14 Debugging 调试 ...................................................................................................... 70
14.1 Logging 记日志 .................................................................................................. 70
14.2 Peer Simulation 对等模拟 .................................................................................. 70
14.3 Record and Replay 记录及答复 .......................................................................... 70
15 Concurrency 并发性 ............................................................................................... 71
15.1 Terminology术语................................................................................................ 71
15.1.1 Concurrency 并发性 ...................................................................................... 72
15.1.2 Contention ......................................................................................................................................... 72
15.1.3 Resource Protection 资源保护 .................................................................................................. 72
15.2 Resolving Contention 解决contention .............................................................. 72
15.2.1 Read Only 只读................................................................................................................................ 72
15.2.2 Atomic Operations 原子操作 ....................................................................................................... 73
15.2.3 Operating System Support 操作系统支持 ................................................................................. 73
15.2.4 Explicit Protection 显式保护 ........................................................................................................ 73
15.2.5 Thread Safe Classes 线程安全类 ................................................................................................. 77
15.2.6 Compartmentalization..................................................................................................................... 77
16 Threads 线程 ........................................................................................................... 78
16.1 What is a Thread? 什么是线程 ........................................................................... 78
16.2 Threading Advantages 多线程的优势 ................................................................. 78
16.2.1 Prioritization 优化........................................................................................................................... 78
16.2.2 Encapsulation封装 .......................................................................................................................... 78
16.2.3 Security 安全性 ............................................................................................................................... 79
16.2.4 Multiple Processors 多处理器...................................................................................................... 79
16.2.5 No Serialization 无序列化 ............................................................................................................. 79
16.3 Processes vs. Threads 进程vs. 线程 .................................................................. 79
16.4 Threads vs. Processes 线程vs. 进程 .................................................................. 80
16.5 Thread Variables 线程变量................................................................................. 80
16.6 Threadable and ThreadSafe ................................................................................. 80
16.6.1 Threadable 可线程的..................................................................................................................... 80
16.6.2 Threadsafe 线程安全的................................................................................................................. 80
16.7 Synchronization .................................................................................................. 81
16.8 TThread .............................................................................................................. 81
16.9 TThreadList ......................................................................................................... 81
16.10 Indy .................................................................................................................. 81
16.11 TIdThread ......................................................................................................... 81
16.12 TIdThreadComponent........................................................................................ 82
16.13 TIdSync ............................................................................................................. 82
16.14 TIdNotify........................................................................................................... 82
16.15 TIdThreadSafe ................................................................................................... 82
16.16 Common Problems 常见的问题........................................................................ 83
16.17 Bottlenecks 瓶颈 .............................................................................................. 83
16.17.1 Critical Section Implementation 临界区实现.......................................................................... 83
16.17.2 TMREWS .......................................................................................................................................... 83
16.17.3 Syncrhonizations 同步 ................................................................................................................. 84
16.17.4 User Interface Updates 用户界面更新 .................................................................................... 84
17 Servers服务器 ........................................................................................................ 85
17.1 Server Types 服务器类型 ................................................................................... 85
17.1.1 TIdTCPServer ..................................................................................................................................... 86
17.1.2 TIdUDPServer .................................................................................................................................... 90
17.1.3 TIdSimpleServer................................................................................................................................ 90
17.2 Threaded Events 线程性的事件.......................................................................... 91
17.3 TCP Server Models TCP服务器模型..................................................................... 91
17.3.1 OnExecute.......................................................................................................................................... 91
17.3.2 Command Handlers ......................................................................................................................... 92
17.4 Command Handlers............................................................................................. 93
17.4.1 Implementation 实现 ..................................................................................................................... 93
17.4.2 Example Protocol 例子协议.......................................................................................................... 94
17.4.3 Base Demo......................................................................................................................................... 94
17.4.4 创建个 Command Handler .......................................................................................................... 94
17.4.5 Command Handler Support............................................................................................................ 96
17.4.6 Testing the New Command 测试新命令 .................................................................................... 97
17.4.7 Implementing HELP 实现HELP .................................................................................................... 97
17.4.8 Implementing DATETIME 实现DATETIME.................................................................................. 98
17.4.9 Conclusion 结论 ............................................................................................................................ 100
17.5 Postal Code Server - OnExecute Implementation ................................................ 100
17.6 Postal Code Server - Command Handlers............................................................ 100
17.7 Thread Management 线程管理 ........................................................................ 100
17.7.1 TIdThreadMgrDefault .................................................................................................................... 100
17.7.2 Thread Pooling 线程池 ................................................................................................................ 101
18 SSL - Secure Sockets 安全Sockets ...................................................................... 102
18.1 Secure HTTP / HTTPS ......................................................................................... 102
18.2 Other Clients ..................................................................................................... 102
18.3 Server SSL ......................................................................................................... 103
18.4 转换证书为 PEM 格式 ................................................................................... 103
18.4.1 Exporting the Certificate 导出证书 ........................................................................................... 103
18.4.2 Convert .pfx to .pem ...................................................................................................................... 103
18.4.3 Splitting the .pem File 拆分 .pem文件 ................................................................................... 104
18.4.4 Key.pem............................................................................................................................................ 104
18.4.5 Cert.pem .......................................................................................................................................... 104
18.4.6 Root.pem ......................................................................................................................................... 104
19 Indy 10 Overview 回顾.................................................................................................................... 105
19.1 Changes ........................................................................................................................................ 105
19.1.1 Separation of Packages Packages的分离................................................................................ 106
19.1.2 SSL Core SSL内核 ..................................................................................................................... 106
19.1.3 SSL Protocols SSL协议............................................................................................................. 106
19.1.4 FTP Client ......................................................................................................................................... 106
19.1.5 FTP Server ........................................................................................................................................ 107
19.1.6 FTP List Parsing FTP列表转换 ............................................................................................... 107
19.1.7 Other 其他 ..................................................................................................................................... 108
19.2 Core Rebuild 内核重构................................................................................................................ 108
19.2.1 IOHandler Restructuring IOHandler 重构 ........................................................................... 109
19.2.2 Network Interfaces 网络接口..................................................................................................... 109
19.2.3 Fibers 纤程 ..................................................................................................................................... 110
19.2.4 Schedulers 调度器 ........................................................................................................................ 110
19.2.5 Work Queues 工作队列............................................................................................................... 112
19.2.6 Chains 链 ........................................................................................................................................ 112
19.2.7 Chain Engines 链引擎 .................................................................................................................. 113
19.2.8 Contexts ........................................................................................................................................... 113


2 0
原创粉丝点击