Never too old to learn.

socket单元

Posted on By Andy Zhu

实现的功能:(即zul_socket的接口部分)

interface
{$mode objfpc}
 uses sockets;
 const
  maxn=1048576;
 type
  Vport=longint;
  Vlabel=longint;
  Tserver=class(TObject)
   port:Vport;
   constructor create;
   constructor create(p:Vport);
   destructor destory;
   procedure init;
   procedure init(p:Vport);
   function accept:Vlabel;
   procedure send(a:ansistring;p:Vlabel);
   function recv(p:Vlabel):ansistring;
   function close(p:Vlabel):boolean;
   function close:boolean;
  end;
  Vhost=string;
  Tclient=class(TObject)
   host:Vhost;
   port:Vport;
   constructor create;
   constructor create(h:Vhost;p:Vport);
   destructor destory;
   procedure init;
   procedure init(h:Vhost;p:Vport);
   function connect:boolean;
   procedure send(s:ansistring);
   function recv:ansistring;
   function close:boolean;
  end;

具体的实现就不扔上来了

编译后的ppuo文件可以在这里下载