6. 交互示例
本示例使用 RFC 726 的术语约定来描述。引用该 RFC 的原文:
"S:" is sent from serving host to using host.
"U:" is sent from using host to serving host.
"T:" is entered by the terminal user.
"P:" is printed on the terminal.
方括号([])中的文字为注释。尖括号(<>)中的文字应视为一个整体单元。例如,回车为 <cr>,十进制值 27 表示为 <27>。
我们假定用户已经建立了 Telnet 连接并已登录,并且某个应用程序刚刚启动,或是由用户直接启动,或是通过预设的启动过程启动。页面上的呈现方式仅仅是为了将各项内容分组,并不意味着消息边界的位置。应当假定对话的任何部分都可以作为一条或多条消息发送。程序或 Telnet 的第一个动作是协商 DET 选项:
S: <IAC><DO><DET>
U: <IAC><WILL><DET>
S:<IAC><DO><OUTPUT PAGE SIZE> [First negotiate the screen
size. In this case we are
U:<IAC><WILL><NAOP> asking the user the size of the
terminal. This could have been
U:<IAC><SB><NAOP><DR><25><IAC><SE> done before the DET option was
negotiated.]
S:<IAC><SB><NAOP><DS><0><IAC><SE>
S:<IAC><DO><OUTPUT LINE WIDTH>
U:<IAC><SB><NAOL><DR><80><IAC><SE> [Defines the screen to be 25
lines by 80 characters.
S:<IAC><SB><NAOL><DS><0><IAC><SE> The server may use this
information when formatting
the screen.]
S:<IAC><SB><DET><FORMAT FACILITIES> [Now set the terminal attributes.]
<Repeat><Protection, 3 Levels
Intensity><IAC><SE>
U:<IAC><SB><DET><FORMAT FACILITIES>
<Repeat, Blinking><Protection, 3
Levels Intensity><IAC><SE>
S:<IAC><SB><DET><ERASE SCREEN><IAC><SE> [Erase the screen and
start sending the form.]
<IAC><SB><DET><FORMAT DATA>
<Protection=1, Intensity=1><0>
<5><IAC><SE>Name:
<IAC><SB><DET><MOVE CURSOR><0><1>
<IAC><SE>
<IAC><SB><DET><FORMAT DATA>
Protection=1, Intensity=1><0>
<8><IAC><SE>
Address:
<IAC><SB><MOVE CURSOR><0><4><IAC>
<SE>
<IAC><SB><DET><FORMAT DATA>
Protection=1, Intensity=1><0>
<17><IAC><SE>
Telephone number:
<IAC><SB><DET><MOVE CURSOR><32><4>
<IAC><SE>
<IAC><SB><DET><FORMAT DATA>
Protection=1, Intensity=1><0>
<24><IAC><SE>
Social Security Number:
<IAC><SB><DET><FORMAT DATA> [Establish a field that doesn't
<Protection=1, Intensity=7> display what is typed into it.]
<0><11><IAC><SE>
<IAC><SB><DET><MOVE CURSOR><32>
<5><IAC><SE>
<IAC><SB><DET><FORMAT FACILITIES> [Get permission to use Blinking
<Blinking><0><IAC><SE> Attribute.]
U:<IAC><SB><DET><FORMAT FACILITIES>
<Repeat, Blinking><Protection,
3 Levels Intensity><IAC><SE>
S:<IAC><SB><DET><FORMAT DATA>
<Blinking=1, Protection=1,
Intensity=1><0><29><IAC><SE>
Your SSN will not be printed.
<IAC><SB><DET><HOME><IAC><SE>
<IAC><GA>
前面的交互已在屏幕上放置了一张表单,其外观如下:
Name:
Address:
Telephone Number: Social Security Number:
"Your SSN will not be printed."
其中带引号的字符串在闪烁。
终端用户现在可以自由填写所提供的表单。他将光标定位到第一个字段的开头(这通常通过按 Tab 键完成)并开始键入。我们没有展示这一交互,因为它不会与 User Telnet 程序或网络产生任何交互。终端用户填完表单后,按下传输键发送表单的未保护部分,但在此之前 User Telnet 程序会先协商 Byte Macro Option,以压缩 Field Separator 子命令:
U:<IAC><DO><BM> [Negotiate Byte Macro Option.]
S:<IAC><WILL><BM> [Define decimal 166 to be the
Field Separator subcommand
U:<IAC><SB><BM><DEFINE> (see Appendix 3)]
<166><6><IAC SB DET FIELD
SEPARATOR IAC SE><IAC><SE>
S:<IAC><SB><BM><ACCEPT><166> [The server accepts the macro.]
<IAC><SE>
U:<IAC><SB><DET><DATA TRANSMIT><0><6>
<IAC><SE>
John Doe <166> 1515 Elm St., Urbana, Il 61801
<166> 217-333-9999 <166> 123-45-6789 <166>
S:<IAC><SB><DET><ERASE SCREEN><IAC><SE>
Thank you.
依此类推。