아래 코드처럼 Client에서 오는 데이터는 AThread.ConnectionCurrentReadBuffer로 받아 Byte변환으로
"104601724034F5B0ACD0B033D" 처럼 읽을 수 있었습니다만(AThread.Connection.ReadLn은 안됨)
Server에서 Ckient로 보낼 때 AThread.Connection.WriteLn으로는 Client에서 받지 못하는데
어떤 함수를 사용해야 하나요?
Write,WriteBuffer 등이 있던데......
도움 바랍니다.
procedure TWSD_Main_F.IdTCPServerExecute(AThread: TIdPeerThread);
var
Msg, resp, snsStr: string;
begin
Msg := AThread.Connection.CurrentReadBuffer;
for i := 5 to length(Msg) do
resp := resp + IntToHex(Byte(Msg[i]),2);
sndStr := '5B0E230B102034FD0345A';
AThread.Connection.WriteLn(sndStr);
end;
procedure TWSD_Main_F.IdTCPServerExecute(AThread: TIdPeerThread);
var
Msg, resp, snsStr: string;
aStream : TMemoryStream;
aLen : integer;
begin
Msg := AThread.Connection.CurrentReadBuffer;
for i := 5 to length(Msg) do
resp := resp + IntToHex(Byte(Msg[i]),2);
sndStr := '5B0E230B102034FD0345A';
aStream := TMemoryStream.Create;
aLen := Length(sndStr);
aStream.WriteBuffer(Pointer(sndStr )^, aLen);
if AThread.Connection.Connected then begin
try
AThread.Connection.OpenWriteBuffer;
AThread.Connection.WriteStream(AStream);
AThread.Connection.CloseWriteBuffer;
except on E:exception do
begin
AThread.Connection.DisconnectSocket;
end;
end;
end;
aStream.Free;
end;
<!--CodeE-->