NMMSG.pas
资源名称:FastNet.rar [点击查看]
上传用户:szzdds
上传日期:2013-09-18
资源大小:293k
文件大小:3k
源码类别:
Delphi控件源码
开发平台:
Delphi
- unit NMMSG;
- {$X+}
- {$R-}
- {$IFDEF VER100}
- {$DEFINE NMF3}
- {$ENDIF}
- {$IFDEF VER110}
- {$DEFINE NMF3}
- {$ENDIF}
- {$IFDEF VER120}
- {$DEFINE NMF3}
- {$ENDIF}
- {$IFDEF VER125}
- {$DEFINE NMF3}
- {$ENDIF}
- interface
- uses
- Classes, SysUtils, Forms, Psock, NMConst, Winsock;
- {$IFDEF VER110}
- {$OBJEXPORTALL On}
- {$ENDIF}
- {$IFDEF VER120}
- {$OBJEXPORTALL On}
- {$ENDIF}
- {$IFDEF VER125}
- {$OBJEXPORTALL On}
- {$ENDIF}
- // CompName='NMMSG32';
- // Major_Version='4';
- // Minor_Version='02';
- // Date_Version='012798';
- type
- TMSGEvent = procedure(Sender: TComponent; const sFrom, sMsg: string) of object;
- TNMMsg = class(TPowerSock)
- private
- sFromName: string;
- FOnMessageSent: TNotifyEvent;
- protected
- public
- constructor Create(AOwner: TComponent); override;
- procedure Abort; override;
- function PostIt(const sMsg: string): string;
- published
- property FromName: string read sFromName write sFromName;
- property OnMessageSent: TNotifyEvent read FOnMessageSent write FOnMessageSent;
- end; {_ TNMMsg = class(TPowerSock) _}
- TNMMSGServ = class(TNMGeneralServer)
- private
- FOnMSG: TMSGEvent;
- protected
- public
- constructor Create(AOwner: TComponent); override;
- procedure Serve; override;
- published
- property OnMSG: TMSGEvent read FOnMSG write FOnMSG;
- end; {_ TNMMSGServ = class(TNMGeneralServer) _}
- implementation
- constructor TNMMsg.Create;
- begin
- inherited Create(AOwner);
- Port := 6711;
- end; {_ constructor TNMMsg.Create; _}
- function TNMMsg.PostIt;
- var i: integer;
- begin
- Connect;
- try
- Write(Format('%.4d', [Length(FromName)]) + FromName);
- Write(Format('%.4d', [Length(sMsg)]) + sMsg);
- if Assigned(FOnMessageSent) then FOnMessageSent(self);
- Result := Read(16);
- finally
- DisConnect;
- end; {_ try _}
- end; {_ function TNMMsg.PostIt; _}
- procedure TNMMsg.Abort;
- begin
- if Connected then
- begin
- Cancel;
- DisConnect;
- end; {_ if connected then _}
- end; {_ procedure TNMMsg.Abort; _}
- {TNMMSGServ}
- constructor TNMMSGServ.Create;
- begin
- inherited Create(AOwner);
- Port := 6711;
- end; {_ constructor TNMMSGServ.Create; _}
- procedure TNMMSGServ.Serve;
- var sFrom, sMsg: string;
- i: integer;
- begin
- try
- i := StrToInt(Read(4));
- if i > 0 then
- sFrom := Read(i);
- i := StrToInt(Read(4));
- if i > 0 then
- sMsg := Read(i)
- else {_ NOT if i > 0 then _} sMsg := '';
- Write('OK' + ' ');
- if Assigned(TNMMSGServ(Chief).FOnMSG) then (TNMMSGServ(Chief).FOnMSG(self, sFrom, sMsg));
- while Connected and (not beencanceled) do
- Wait;
- except
- end;
- end; {_ procedure TNMMSGServ.Serve; _}
- end.