W
wlmmlw
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.FormCreate(Sender: TObject);
begin
ss.Open;
cs.Open;
end;
procedure TForm1.ssClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
reinfo.Lines.Add('Connect from '+socket.RemoteAddress);
end;
procedure TForm1.btnSendDataClick(Sender: TObject);
var
buf: TMemoryStream;
begin
buf := TMemoryStream.Create;
if od1.Execute then begin
buf.LoadFromFile(od1.FileName);
// recs.Lines.SaveToStream(buf);
buf.Position := 0;
cs.Socket.SendStream(buf);
// cs.Socket.SendStreamThenDrop(buf);
end;
end;
procedure TForm1.ssClientWrite(Sender: TObject; Socket: TCustomWinSocket);
begin
reinfo.Lines.Add('Send to ' + Socket.RemoteAddress);
end;
procedure TForm1.ssClientRead(Sender: TObject; Socket: TCustomWinSocket);
var
rc: Integer;
rs: TStrings;
begin
reinfo.Lines.Add('Receive from ' + Socket.RemoteAddress);
reinfo.Lines.Add('Receive '+ Inttostr(Socket.ReceiveLength) + ' Bytes');
Buf.SetSize(Socket.ReceiveLength);
Socket.ReceiveBuf(buf,Socket.ReceiveLength);
rs := TStringList.Create;
try
rs.Text := Socket.ReceiveText;
rs.SaveToFile('c:/ss.txt');
finally
rs.Free;
end;
end; ///以上的过程总是有错,如果不用Socket.ReceiveBuf就不会有错
initialization
buf := TMemoryStream.Create;
finalization
buf.free;
end.
begin
ss.Open;
cs.Open;
end;
procedure TForm1.ssClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
reinfo.Lines.Add('Connect from '+socket.RemoteAddress);
end;
procedure TForm1.btnSendDataClick(Sender: TObject);
var
buf: TMemoryStream;
begin
buf := TMemoryStream.Create;
if od1.Execute then begin
buf.LoadFromFile(od1.FileName);
// recs.Lines.SaveToStream(buf);
buf.Position := 0;
cs.Socket.SendStream(buf);
// cs.Socket.SendStreamThenDrop(buf);
end;
end;
procedure TForm1.ssClientWrite(Sender: TObject; Socket: TCustomWinSocket);
begin
reinfo.Lines.Add('Send to ' + Socket.RemoteAddress);
end;
procedure TForm1.ssClientRead(Sender: TObject; Socket: TCustomWinSocket);
var
rc: Integer;
rs: TStrings;
begin
reinfo.Lines.Add('Receive from ' + Socket.RemoteAddress);
reinfo.Lines.Add('Receive '+ Inttostr(Socket.ReceiveLength) + ' Bytes');
Buf.SetSize(Socket.ReceiveLength);
Socket.ReceiveBuf(buf,Socket.ReceiveLength);
rs := TStringList.Create;
try
rs.Text := Socket.ReceiveText;
rs.SaveToFile('c:/ss.txt');
finally
rs.Free;
end;
end; ///以上的过程总是有错,如果不用Socket.ReceiveBuf就不会有错
initialization
buf := TMemoryStream.Create;
finalization
buf.free;
end.