bestlong 怕失憶論壇

 

 

搜索
bestlong 怕失憶論壇 論壇 Delphi 利用 TCP/IP 作檔案續傳
查看: 4361|回復: 0
go

利用 TCP/IP 作檔案續傳 [複製鏈接]

Rank: 9Rank: 9Rank: 9

1#
發表於 2006-6-23 17:24 |只看該作者 |倒序瀏覽 |打印
利用 TWinSocketStream 可以做到
  1. var
  2.   TServerWinSocket serverSocket;
  3.   TClientWinSocket clientSocket;
  4.   TFileStream inFile, outFile;
  5.   // 假設各 Stream 都已 created

  6. // 在 Server 端
  7. // Client send 一個命令告知 Server 要由 536 bytes 開始傳
  8. inFile.Position := 536;
  9. wtih TWinSocketStream.Create(serverSocket, 60000) do
  10. begin
  11.   CopyFrom(inFile, inFile.Size - inFile.Position + 1);
  12.   Free;
  13. end;

  14. // 在 Client 端 OnReadEvent 中
  15. memStream = TMemoryStream.Create;
  16. memStream.Size = TOTAL_FILE_SIZE;
  17. memStream.Position := 0;
  18. socketStream := TWinSocketStream.Create(clientSocket, 60000) do
  19. if socketStream.WaitForData(60000) then // give the client 60 seconds writing
  20.   socketStream.Read(PCharArray(memStream.Memory)^, TOTAL_FILE_SIZE)
  21. memStream.Position := 0;
  22. outFile.Position := 536;
  23. outFile.CopyFrom(memStream);

  24. // 释放全部的对象
複製代碼
我是雪龍
http://blog.bestlong.idv.tw
http://www.bestlong.idv.tw
‹ 上一主題|下一主題

Archiver|怕失憶論壇

GMT+8, 2024-5-5 11:40 , Processed in 0.010624 second(s), 10 queries .

Powered by Discuz! X1.5

© 2001-2010 Comsenz Inc.