我在做什么:我的服务器通过上下文列表发送数据,并在锁定到特定客户端后发送该客户端数据,并且它期望我们在此连接计时器中处理的回复。我知道使用线程会是一种更好的方法,但这就是我所采用的。
这是我的问题:我请求获取连接信息并且它工作正常,套接字写入行 getstring 数据 1 到 8 但是当我写“Hello”时它没有响应任何数据它只是断开客户端。
任何帮助将不胜感激尝试解决这个问题 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;