📄 nmstrm.pas
字号:
{$IFDEF VER100}
{$DEFINE NMF3}
{$ENDIF}
{$IFDEF VER110}
{$DEFINE NMF3}
{$ENDIF}
{$IFDEF VER120}
{$DEFINE NMF3}
{$ENDIF}
{$IFDEF VER125}
{$DEFINE NMF3}
{$ENDIF}
unit NMSTRM;
interface
uses
SysUtils, Classes, Forms, Psock, NMConst;
{$IFDEF VER110}
{$OBJEXPORTALL On}
{$ENDIF}
{$IFDEF VER120}
{$OBJEXPORTALL On}
{$ENDIF}
{$IFDEF VER125}
{$OBJEXPORTALL On}
{$ENDIF}
// CompName='NMSTRM32';
// Major_Version='4';
// Minor_Version='02';
// Date_Version='012798';
type
TStrmEvent = procedure(Sender: TComponent; const sFrom: string; strm: Tstream) of object;
TNMStrm = class(TPowerSock)
private
sFromName: string;
FOnMessageSent: TNotifyEvent;
protected
public
constructor Create(AOwner: TComponent); override;
procedure Abort; override;
function PostIt(const sStrm: Tstream): string;
published
property OnPacketRecvd;
property OnPacketSent;
property FromName: string read sFromName write sFromName;
property OnMessageSent: TNotifyEvent read FOnMessageSent write FOnMessageSent;
end; {_ TNMStrm = class(TPowerSock) _}
TNMStrmServ = class(TNMGeneralServer)
private
FOnMSG: TStrmEvent;
protected
public
constructor Create(AOwner: TComponent); override;
procedure Serve; override;
published
property OnMSG: TStrmEvent read FOnMSG write FOnMSG;
end; {_ TNMStrmServ = class(TNMGeneralServer) _}
implementation
constructor TNMStrm.Create;
begin
inherited Create(AOwner);
Port := 6711;
end; {_ constructor TNMStrm.Create; _}
function TNMStrm.PostIt;
begin
Connect;
try
Write(Format('%.4d', [Length(FromName)]) + FromName);
Write(Format('%10d', [sStrm.size]));
SendStream(sStrm);
if Assigned(FOnMessageSent) then FOnMessageSent(self);
Result := Read(16);
finally
Disconnect;
end; {_ try _}
end; {_ function TNMStrm.PostIt; _}
procedure TNMStrm.Abort;
begin
if connected then
begin
cancel;
Disconnect;
end; {_ if connected then _}
end; {_ procedure TNMStrm.Abort; _}
constructor TNMStrmServ.Create;
begin
inherited Create(AOwner);
Port := 6711;
end; {_ constructor TNMStrmServ.Create; _}
procedure TNMStrmServ.Serve;
var sFrom: string;
Stg: string;
i: longint;
st: TMemorystream;
begin
st := TMemorystream.Create;
try
Stg := Read(4);
i := StrToInt(Stg);
if i > 0 then
sFrom := Read(i);
Stg := Read(10);
i := StrToInt(Stg);
FBytesRecvd := 0;
FBytesTotal := i;
try
if i > 0 then
CaptureStream(st, i);
finally
Write('OK' + ' ');
end;
st.position := 0;
if Assigned(TNMStrmServ(Chief).FOnMSG) then TNMStrmServ(Chief).FOnMSG(self, sFrom, st);
finally
st.free;
while connected and (not beencanceled) do
Wait;
end; {_ try _}
end; {_ procedure TNMStrmServ.Serve; _}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -