2
200103067
Unregistered / Unconfirmed
GUEST, unregistred user!
Server端代码:
procedure TFrmServer.IdTCPServer1Execute(AThread: TIdPeerThread);
var
RecvStr: string;
RecvStream,SendStream : TMemoryStream;
begin
RecvStream := TMemoryStream.Create;
AThread.Connection.ReadStream(RecvStream, -1, true);
RecvStream.Position := 0;
SetLength(RecvStr, RecvStream.size);
LbLog.Lines.Add('收到的数据:'+ RecvStr);
RecvStream.Free;
SendStream := TMemoryStream.Create;
SendStream.LoadFromFile(ExtractFilePath(paramstr(0)) +ServerToClientStream.dat);
SendStream.Position := 0;
AThread.Connection.WriteStream(SendStream);
SendStream.Free;
AThread.Connection.DisConnect;
end;
Client端代码:
procedure TClientHandleThread.HandleShow;
var
RecvStream: TMemoryStream;
RecvStr:string;
begin
RecvStream := TMemoryStream.Create;
FrmClient.IdTCPClient1.ReadStream(RecvStream, -1, true);
RecvStream.Position := 0;
SetLength(RecvStr, RecvStream.size);
FrmClient.Memo1.Text :='收到数据'+RecvStr;
RecvStream.Free;
end;
procedure TClientHandleThread.Execute;
begin
while not Terminated do
begin
if FrmClient.IdTCPClient1.Connected then
begin
Synchronize(HandleShow);
Sleep(100);
end;
end;
end;
procedure TFrmClient.SendToServerClick(Sender: TObject);
var
MyStream: TMemoryStream;
begin
ClientHandleThread := TClientHandleThread.Create(False);
MyStream := TMemoryStream.Create;
MyStream.LoadFromFile(ExtractFilePath(paramstr(0))+ClientToServerStream.dat);
MyStream.Position := 0;
IdTCPClient1.Connect;
IdTCPClient1.writestream(MyStream);
IdTCPClient1.Disconnect;
MyStream.Free;
end;
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Server端AThread.Connection.WriteStream(SendStream);出错,好象是说未连接,如果去掉Client端的IdTCPClient1.Disconnect; Server器端无法接收数据,谢谢赐教!!!
procedure TFrmServer.IdTCPServer1Execute(AThread: TIdPeerThread);
var
RecvStr: string;
RecvStream,SendStream : TMemoryStream;
begin
RecvStream := TMemoryStream.Create;
AThread.Connection.ReadStream(RecvStream, -1, true);
RecvStream.Position := 0;
SetLength(RecvStr, RecvStream.size);
LbLog.Lines.Add('收到的数据:'+ RecvStr);
RecvStream.Free;
SendStream := TMemoryStream.Create;
SendStream.LoadFromFile(ExtractFilePath(paramstr(0)) +ServerToClientStream.dat);
SendStream.Position := 0;
AThread.Connection.WriteStream(SendStream);
SendStream.Free;
AThread.Connection.DisConnect;
end;
Client端代码:
procedure TClientHandleThread.HandleShow;
var
RecvStream: TMemoryStream;
RecvStr:string;
begin
RecvStream := TMemoryStream.Create;
FrmClient.IdTCPClient1.ReadStream(RecvStream, -1, true);
RecvStream.Position := 0;
SetLength(RecvStr, RecvStream.size);
FrmClient.Memo1.Text :='收到数据'+RecvStr;
RecvStream.Free;
end;
procedure TClientHandleThread.Execute;
begin
while not Terminated do
begin
if FrmClient.IdTCPClient1.Connected then
begin
Synchronize(HandleShow);
Sleep(100);
end;
end;
end;
procedure TFrmClient.SendToServerClick(Sender: TObject);
var
MyStream: TMemoryStream;
begin
ClientHandleThread := TClientHandleThread.Create(False);
MyStream := TMemoryStream.Create;
MyStream.LoadFromFile(ExtractFilePath(paramstr(0))+ClientToServerStream.dat);
MyStream.Position := 0;
IdTCPClient1.Connect;
IdTCPClient1.writestream(MyStream);
IdTCPClient1.Disconnect;
MyStream.Free;
end;
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Server端AThread.Connection.WriteStream(SendStream);出错,好象是说未连接,如果去掉Client端的IdTCPClient1.Disconnect; Server器端无法接收数据,谢谢赐教!!!