我在做什么: 我的服务器通过上下文列表发送数据,并在它锁定到特定客户端后发送该客户端数据,并且它期望我们在此连接中处理的答复计时器。 我明白,使用线程将是一个更好的方法来做到这一点,但这是我一起去的。Delphi Indy 10断开连接问题
这里是我的问题: 我请求得到连接信息,它工作正常,插座写入线GetString的数据1 throught 8 但是当我写“你好”它不只是断开客户端的数据作出反应。
任何帮助将不胜感激,试图找出这个为期2天左右。 在此先感谢!
这里是我的代码:
procedure TForm1.CommandTimerTimer(Sender: TObject);
var
sl:Tstringlist;
Command: String;
begin
if clientsocket.IOHandler.InputBufferIsEmpty then
begin
clientsocket.IOHandler.CheckForDataOnSource(10);
if clientsocket.IOHandler.InputBufferIsEmpty then Exit;
end;
Command := clientsocket.IOHandler.ReadLn();
sl:= Tstringlist.Create;
sl.Delimiter:= '|';
sl.StrictDelimiter:=true;
sl.DelimitedText:= Command;
if sl[0] = 'did i get data' then
begin
showmessage('Yea I got Data');
end;
if sl[0] = 'BroadCasted Message' then
begin
Clientsocket.IOHandler.write('data');
showmessage(sl[1]); // This is data sent from my server to this client, in order to manage the data I have created a Tstringlist and delimited it out by '|'.
end;
if sl[0] = 'hello' then
begin
clientsocket.IOHandler.write('data');
end;
if sl[0] = 'Get Connection Info' then
begin
// This part
clientsocket.IOHandler.writeln('Newconnection' + '|' + 'string data 1' + '|' + 'string data 2' + '|' + 'string data 3' + '|'+ 'string data 4'+'|' + 'string data 5'+'|'+'string data 6'+'|'+'string data 7'+'|'+'string data 8');
end;
if sl[0] = 'Reconnect' then
begin
commandtimer.Enabled:=false;
Connectiontimer.Enabled:=true; // This is a timer that constantly checks and keeps the TidTCPclientsocket connected with my server as this is a Reverse connection Protocol.
Exit;
end;
commandtimer.enabled:=true;
end;
您正在使用'WriteLn()'作为''Get Connection Info''回复,但正在使用'Write()'作为其他回复。服务器是否期望在每个回复中都有换行符? – 2013-05-06 03:44:13