全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1460
推到 Plurk!
推到 Facebook!

Socket

 
jumo
一般會員


發表:33
回覆:65
積分:24
註冊:2002-04-17

發送簡訊給我
#1 引用回覆 回覆 發表時間:2002-07-14 16:18:55 IP:61.221.xxx.xxx 未訂閱
以下是一個用ServerSocket, ClientSocket 傳檔的程式, 但是檔案大小會不依樣, 請教各位高手應該如何修改, 謝謝!! ------------------------------------------------------------------- unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ScktComp, StdCtrls; type TForm1 = class(TForm) ClientSocket1: TClientSocket; ServerSocket1: TServerSocket; btnTestSockets: TButton; procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket); procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure ClientSocket1Disconnect(Sender: TObject; Socket: TCustomWinSocket); procedure ClientSocket1Connect(Sender: TObject; Socket: TCustomWinSocket); procedure ServerSocket1ClientConnect(Sender: TObject; Socket: TCustomWinSocket); procedure btnTestSocketsClick(Sender: TObject); private FStream: TFileStream; { Private-Deklarationen } public { Public-Deklarationen } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket); var iLen: Integer; Bfr: Pointer; begin iLen := Socket.ReceiveLength; GetMem(Bfr, iLen); try Socket.ReceiveBuf(Bfr^, iLen); FStream.Write(Bfr^, iLen); finally FreeMem(Bfr); end; end; procedure TForm1.FormCreate(Sender: TObject); begin FStream := nil; end; procedure TForm1.FormDestroy(Sender: TObject); begin if Assigned(FStream) then begin FStream.Free; FStream := nil; end; end; procedure TForm1.ClientSocket1Disconnect(Sender: TObject; Socket: TCustomWinSocket); begin if Assigned(FStream) then begin FStream.Free; FStream := nil; end; end; procedure TForm1.ClientSocket1Connect(Sender: TObject; Socket: TCustomWinSocket); begin FStream := TFileStream.Create('c:\temp\test.stream.html', fmCreate or fmShareDenyWrite); end; procedure TForm1.ServerSocket1ClientConnect(Sender: TObject; Socket: TCustomWinSocket); begin Socket.SendStream(TFileStream.Create('c:\temp\test.html', fmOpenRead or fmShareDenyWrite)); end; procedure TForm1.btnTestSocketsClick(Sender: TObject); begin ServerSocket1.Active := True; ClientSocket1.Active := True; end;
系統時間:2017-10-19 13:28:24
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!