1
Indy In Depth
Indy is Copyright (c) 1993 - 2002, Chad Z. Hower (Kudzu)
and the Indy Pit Crew -http:/www.nevrona.com/Indy/
译者注:
本人利用业余时间本着学习的目的,学习并翻译此 Indy 官方文档。只限于学习交流,禁止
用于任何商业目的。Demo等可以在 Indy 的官网 http://www.atozedsoftware.com/index.en.aspx
获得。第一部分----介绍 和 第二部分 ----- 技术支持 和 最后两个部分 ------福利资料及作
者介绍 未翻译。
翻译时译者尽量保持原版排版,由于此文档年代久远,很多代码在 delphi 新版本中已经不能
使用或者需要一定的修改方能使用,对于知道怎么修改的,译者已经直接进行了修改,对于
一些有疑问或问题的,译者用不同颜色的字做了标注。由于译者能力有限,翻译中难免存在
一定的问题,敬请联系我指正,谢谢!
转发请注明译者或者保留这一页。
联系方式:
あの夏の白い云
QQ:350645157
2
目录
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
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
4
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
5
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