P
popoaleck
Unregistered / Unconfirmed
GUEST, unregistred user!
使用Indy的IdTcpServer控件,监听一个TCP端口,当客户端发送数据过来时接收该数据.客户端以字节流的方式发送数据.请帮我看看接受程序哪里有问题.现在只要执行到Read那里就会出错.
procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
var
stream: TStream;
str1, str2: array [0..15] of char;
begin
try
if AThread.Connection.Connected then
begin
stream := TStream.Create;
Athread.Connection.ReadStream(stream);
FillChar(str1, 16, 0);
if stream.Read(str1, 16) > 0 then
memo1.Lines.Append('client send:' + str1);
end;
except
end;
end;
procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
var
stream: TStream;
str1, str2: array [0..15] of char;
begin
try
if AThread.Connection.Connected then
begin
stream := TStream.Create;
Athread.Connection.ReadStream(stream);
FillChar(str1, 16, 0);
if stream.Read(str1, 16) > 0 then
memo1.Lines.Append('client send:' + str1);
end;
except
end;
end;