📄 wsocket.pas
字号:
function GetSockName(var saddr : TSockAddrIn; var saddrlen : Integer) : integer; virtual;
procedure SetLingerOption;
procedure Dup(NewHSocket : TSocket); virtual;
procedure Shutdown(How : Integer); virtual;
procedure Pause; virtual;
procedure Resume; virtual;
procedure PutDataInSendBuffer(Data : Pointer; Len : Integer);
procedure PutStringInSendBuffer(Str : String);
procedure DeleteBufferedData;
procedure MessagePump; virtual;
{$IFNDEF VER80}
procedure MessageLoop;
function ProcessMessage : Boolean;
procedure ProcessMessages;
{$ENDIF}
{$IFDEF NOFORMS}
property Terminated : Boolean read FTerminated
write FTerminated;
property OnMessagePump : TNotifyEvent read FOnMessagePump
write FOnMessagePump;
{$ENDIF}
protected
property PortNum : Integer read FPortNum;
property Handle : HWND read FWindowHandle;
property HSocket : TSocket read FHSocket
write Dup;
property Addr : string read GetAddr
write SetAddr;
property Port : string read GetRemotePort
write SetRemotePort;
property LocalPort : string read FLocalPortStr
write SetLocalPort;
property Proto : String read GetProto
write SetProto;
property MultiThreaded : Boolean read FMultiThreaded
write FMultiThreaded;
property PeerAddr : String read GetPeerAddr;
property PeerPort : String read GetPeerPort;
property DnsResult : String read FDnsResult;
property DnsResultList : TStrings read FDnsResultList;
property State : TSocketState read FState;
property AllSent : Boolean read bAllSent;
property ReadCount : LongInt read FReadCount;
property RcvdCount : LongInt read GetRcvdCount;
property LastError : Integer read FLastError;
property BufSize : Integer read FBufSize
write FBufSize;
property OnDataAvailable : TDataAvailable read FOnDataAvailable
write FOnDataAvailable;
property OnDataSent : TDataSent read FOnDataSent
write FOnDataSent;
property OnSessionClosed : TSessionClosed read FOnSessionClosed
write FOnSessionClosed;
property OnSessionAvailable : TSessionAvailable read FOnSessionAvailable
write FOnSessionAvailable;
property OnSessionConnected : TSessionConnected read FOnSessionConnected
write FOnSessionConnected;
property OnChangeState : TChangeState read FOnChangeState
write FOnChangeState;
property OnLineTooLong : TNotifyEvent read FOnLineTooLong
write FOnLineTooLong;
property OnDnsLookupDone : TDnsLookupDone read FOnDnsLookupDone
write FOnDnsLookupDone;
property OnError : TNotifyEvent read FOnError
write FOnError;
property OnBgException : TBgExceptionEvent read FOnBgException
write FOnBgException;
property FlushTimeout : Integer read FFlushTimeOut
write FFlushTimeout;
property SendFlags : TSocketSendFlags read GetSendFlags
write SetSendFlags;
property Text: String read ReceiveStr
write SendText;
property LingerOnOff : TSocketLingerOnOff read FLingerOnOff
write FLingerOnOff;
property LingerTimeout : Integer read FLingerTimeout
write FLingerTimeout;
{$IFDEF VER80}
property TrumpetCompability : Boolean read FTrumpetCompability
write FTrumpetCompability;
{$ENDIF}
property OnDisplay : TDebugDisplay read FOnDisplay
write FOnDisplay;
end;
TSocksState = (socksData, socksNegociateMethods, socksAuthenticate, socksConnect);
TSocksAuthentication = (socksNoAuthentication, socksAuthenticateUsercode);
TSocksAuthState = (socksAuthStart, socksAuthSuccess, socksAuthFailure, socksAuthNotRequired);
TSocksAuthStateEvent = procedure(Sender : TObject; AuthState : TSocksAuthState) of object;
TSocksErrorEvent = procedure(Sender : TObject; Error : Integer; Msg : String) of Object;
TCustomSocksWSocket = class(TCustomWSocket)
protected
FSocksState : TSocksState;
FSocksServer : String;
FSocksLevel : String;
FSocksPort : String;
FSocksPortAssigned : Boolean;
FSocksServerAssigned : Boolean;
FSocksUsercode : String;
FSocksPassword : String;
FSocksAuthentication : TSocksAuthentication;
FSocksAuthNumber : char;
FBoundAddr : String;
FBoundPort : String;
FRcvBuf : array [0..127] of char;
FRcvCnt : Integer;
FRcvdCnt : Integer;
FRcvdPtr : PChar;
FOnSocksError : TSocksErrorEvent;
FOnSocksConnected : TSessionConnected;
FOnSocksAuthState : TSocksAuthStateEvent;
procedure AssignDefaultValue; override;
procedure TriggerSessionConnected(Error : Word); override;
procedure TriggerSocksConnected(Error : Word); virtual;
procedure TriggerSessionClosed(Error : Word); override;
function TriggerDataAvailable(Error : Word) : Boolean; override;
procedure SetSocksPort(sPort : String); virtual;
procedure SetSocksServer(sServer : String); virtual;
procedure TriggerSocksError(Error : Integer; Msg : String); virtual;
procedure TriggerSocksAuthState(AuthState : TSocksAuthState);
function GetRcvdCount : LongInt; override;
procedure SetSocksLevel(newValue : String);
function DoRecv(var Buffer;
BufferSize : Integer;
Flags : Integer) : Integer; override;
procedure SocksDoConnect;
procedure SocksDoAuthenticate;
procedure DataAvailableError(ErrCode : Integer; Msg : String);
public
procedure Connect; override;
procedure Listen; override;
protected
property SocksServer : String read FSocksServer
write SetSocksServer;
property SocksLevel : String read FSocksLevel
write SetSocksLevel;
property SocksPort : String read FSocksPort
write SetSocksPort;
property SocksUsercode : String read FSocksUsercode
write FSocksUsercode;
property SocksPassword : String read FSocksPassword
write FSocksPassword;
property SocksAuthentication : TSocksAuthentication
read FSocksAuthentication
write FSocksAuthentication;
property OnSocksError : TSocksErrorEvent read FOnSocksError
write FOnSocksError;
property OnSocksConnected : TSessionConnected read FOnSocksConnected
write FOnSocksConnected;
property OnSocksAuthState : TSocksAuthStateEvent
read FOnSocksAuthState
write FOnSocksAuthState;
end;
TCustomLineWSocket = class (TCustomSocksWSocket)
protected
FRcvdPtr : PChar;
FRcvBufSize : Integer;
FRcvdCnt : Integer;
FLineEnd : String;
FLineMode : Boolean;
FLineLength : Integer; { When a line is available }
FLineReceivedFlag : Boolean;
FLineEcho : Boolean; { Echo received data }
FLineEdit : Boolean; { Edit received data }
FTimeout : LongInt; { Given in milliseconds }
FTimeStop : LongInt; { Milliseconds }
procedure WndProc(var MsgRec: TMessage); override;
procedure WMTriggerDataAvailable(var msg: TMessage); message WM_TRIGGER_DATA_AVAILABLE;
function TriggerDataAvailable(Error : Word) : Boolean; override;
procedure TriggerSessionClosed(Error : Word); override;
procedure SetLineMode(newValue : Boolean); virtual;
procedure EditLine(var Len : Integer); virtual;
function GetRcvdCount : LongInt; override;
function DoRecv(var Buffer;
BufferSize : Integer;
Flags : Integer) : Integer; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property LineLength : Integer read FLineLength;
published
property LineMode : Boolean read FLineMode
write SetLineMode;
property LineEnd : String read FLineEnd
write FLineEnd;
property LineEcho : Boolean read FLineEcho
write FLineEcho;
property LineEdit : Boolean read FLineEdit
write FLineEdit;
end;
TCustomSyncWSocket = class(TCustomLineWSocket)
protected
FLinePointer : ^String;
function Synchronize(Proc : TWSocketSyncNextProc; var DoneFlag : Boolean) : Integer; virtual;
function WaitUntilReady(var DoneFlag : Boolean) : Integer; virtual;
procedure InternalDataAvailable(Sender: TObject; Error: Word);
public
procedure ReadLine(Timeout : integer; var Buffer : String);
end;
TWSocket = class(TCustomSyncWSocket)
public
property PortNum;
property Handle;
property HSocket;
property BufSize;
property Text;
property AllSent;
{$IFDEF VER80}
property TrumpetCompability;
{$ENDIF}
property OnDisplay;
published
property Addr;
property Port;
property Proto;
property LocalPort;
property PeerPort;
property PeerAddr;
property DnsResult;
property DnsResultList;
property State;
property ReadCount;
property RcvdCount;
property LastError;
property MultiThreaded;
property OnDataAvailable;
property OnDataSent;
property OnSessionClosed;
property OnSessionAvailable;
property OnSessionConnected;
property OnSocksConnected;
property OnChangeState;
property OnLineTooLong;
property OnDnsLookupDone;
property OnError;
property OnBgException;
property FlushTimeout;
property SendFlags;
property LingerOnOff;
property LingerTimeout;
property SocksLevel;
property SocksServer;
property SocksPort;
property SocksUsercode;
property SocksPassword;
property SocksAuthentication;
property OnSocksError;
property OnSocksAuthState;
end;
TSocksWSocket = class(TWSocket)
end;
procedure Register;
function WinsockInfo : TWSADATA;
function WSocketErrorDesc(error: integer) : string;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -