原文出处 «windows网络编程技术»第8章 完成端口模型
【程序编程相关:在WIN2000/XP下添加自定义纸张的】
由于原书附的是c代码,我把其翻译成delphi代码. 【推荐阅读:三层数据库与应用程序服务器的小型介绍(D】
【扩展信息:Delphi2005学习笔记4(续)——】
其中winsock2.pas在delphi中不带,要另外下载http://jungla.dit.upm.es/~bti/files/winsock2.pas
program completionio;
{$apptype console}
uses
sysutils, winsock2 in winsock2.pas, mains in mains.pas;begin
main(); end.
// module name: iocmplt.cpp
// // description: // // this sample illustrates how to develop a simple echo server winsock // application using the completeion port i/o model. this // sample is implemented as a console-style application and simply prints // messages when connections are established and removed from the server. // the application listens for tcp connections on port 5150 and accepts them // as they arrive. when this application receives data from a client, it // simply echos (this is why we call it an echo server) the data back in // its original form until the client closes the connection. // // 2005-2-5 // cpp convert to delphi pas by johnson //unit mains;
interface
uses windows, winsock2, winsock, sysutils;
const
port = 5150; data_bufsize = 8192; type lpvoid = pointer; lpper_io_operation_data = ^ per_io_operation_data ; per_io_operation_data = packed record overlapped: overlapped; databuf: twsabuf; buffer: array [0..data_bufsize] of char; bytessend: dword; bytesrecv: dword; end;... 下一页