【发布时间】:2015-08-12 09:17:53
【问题描述】:
为什么这段代码的行为不可预测?
procedure ConnectToShell(ID: Integer; Password: String);
var
cmd:String;
begin
if (ID <> Length(ContextList) - 1)
or (ContextList[ID].Context.Connection = nil) then
writeln('This user not found')
else begin
ContextList[ID].Context.Connection.Socket.WriteLn('AUTH 1.0');
Path := ContextList[ID].Context.Connection.Socket.ReadLnWait();
if ContextList[ID].Context.Connection.Socket.ReadLnWait() = 'ADMIT' then
begin
ContextList[ID].Context.Connection.Socket.WriteLn(Password);
if ContextList[ID].Context.Connection.Socket.ReadLnWait() = 'GRANTED' then
begin
ActiveU := ID;
writeln('Access granted');
end else
writeln('Access is denied');
end else
writeln('Access id denied');
end;
end;
它的作用。这是来自服务器程序的代码。服务器侦听新客户端,并将它们的“上下文:IdContext”添加到 TUser 数组中。 TUser 是一条记录,包含三个字段:HostName、ID 和 Context。
在此代码程序中,尝试从数组“连接(授权)”到客户端。它需要 ID(数组中的索引)并发送命令“AUTH 1.0”,然后等待 Path(文件夹的路径)。之后,客户端必须发送“ADMIT”字样。之后,服务器发送一个密码,客户端检查它,如果一切正常,它必须发送“GRANTED”。
代替客户端,我在 Raw 模式下使用 Putty。 Putty 获得“AUTH 1.0”,我写道:
C:\
承认
我有一个问题。此时服务器没有发送密码,他在等我不知道是什么……但是如果我反复发送“ADMIT”,服务器仍然给我发送了密码。与“GRANTED”相同的故事。
【问题讨论】: