私がやっていること: 私のサーバーはコンテキストリストを通過してデータを送信し、特定のクライアントにロックオンした後、そのクライアントデータを送信し、この接続タイマーで処理する応答を期待します。スレッドを使用する方がこれを行うためのより良い方法であることは理解していますが、これが私が行ったことです。
ここに私の問題があります: 接続情報の取得を要求すると、正常に動作します。ソケットは行 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;