PageRenderTime 27ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/synapse/blcksock.pas

http://delphistompclient.googlecode.com/
Pascal | 1554 lines | 608 code | 232 blank | 714 comment | 3 complexity | da67418d1d5bb7f4a7681ff185978b47 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. {==============================================================================|
  2. | Project : Ararat Synapse | 009.006.000 |
  3. |==============================================================================|
  4. | Content: Library base |
  5. |==============================================================================|
  6. | Copyright (c)1999-2008, Lukas Gebauer |
  7. | All rights reserved. |
  8. | |
  9. | Redistribution and use in source and binary forms, with or without |
  10. | modification, are permitted provided that the following conditions are met: |
  11. | |
  12. | Redistributions of source code must retain the above copyright notice, this |
  13. | list of conditions and the following disclaimer. |
  14. | |
  15. | Redistributions in binary form must reproduce the above copyright notice, |
  16. | this list of conditions and the following disclaimer in the documentation |
  17. | and/or other materials provided with the distribution. |
  18. | |
  19. | Neither the name of Lukas Gebauer nor the names of its contributors may |
  20. | be used to endorse or promote products derived from this software without |
  21. | specific prior written permission. |
  22. | |
  23. | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
  24. | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
  25. | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
  26. | ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR |
  27. | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
  28. | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
  29. | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
  30. | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
  31. | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
  32. | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
  33. | DAMAGE. |
  34. |==============================================================================|
  35. | The Initial Developer of the Original Code is Lukas Gebauer (Czech Republic).|
  36. | Portions created by Lukas Gebauer are Copyright (c)1999-2008. |
  37. | All Rights Reserved. |
  38. |==============================================================================|
  39. | Contributor(s): |
  40. |==============================================================================|
  41. | History: see HISTORY.HTM from distribution package |
  42. | (Found at URL: http://www.ararat.cz/synapse/) |
  43. |==============================================================================}
  44. {
  45. Special thanks to Gregor Ibic <gregor.ibic@intelicom.si>
  46. (Intelicom d.o.o., http://www.intelicom.si)
  47. for good inspiration about SSL programming.
  48. }
  49. {$DEFINE ONCEWINSOCK}
  50. {Note about define ONCEWINSOCK:
  51. If you remove this compiler directive, then socket interface is loaded and
  52. initialized on constructor of TBlockSocket class for each socket separately.
  53. Socket interface is used only if your need it.
  54. If you leave this directive here, then socket interface is loaded and
  55. initialized only once at start of your program! It boost performace on high
  56. count of created and destroyed sockets. It eliminate possible small resource
  57. leak on Windows systems too.
  58. }
  59. //{$DEFINE RAISEEXCEPT}
  60. {When you enable this define, then is Raiseexcept property is on by default
  61. }
  62. {:@abstract(Synapse's library core)
  63. Core with implementation basic socket classes.
  64. }
  65. {$IFDEF FPC}
  66. {$MODE DELPHI}
  67. {$ENDIF}
  68. {$IFDEF VER125}
  69. {$DEFINE BCB}
  70. {$ENDIF}
  71. {$IFDEF BCB}
  72. {$ObjExportAll On}
  73. {$ENDIF}
  74. {$Q-}
  75. {$H+}
  76. {$M+}
  77. unit blcksock;
  78. interface
  79. uses
  80. SysUtils, Classes,
  81. synafpc,
  82. synsock, synautil, synacode, synaip
  83. {$IFDEF CIL}
  84. ,System.Net
  85. ,System.Net.Sockets
  86. ,System.Text
  87. {$ENDIF}
  88. ;
  89. const
  90. SynapseRelease = '38';
  91. cLocalhost = '127.0.0.1';
  92. cAnyHost = '0.0.0.0';
  93. cBroadcast = '255.255.255.255';
  94. c6Localhost = '::1';
  95. c6AnyHost = '::0';
  96. c6Broadcast = 'ffff::1';
  97. cAnyPort = '0';
  98. CR = #$0d;
  99. LF = #$0a;
  100. CRLF = CR + LF;
  101. c64k = 65536;
  102. type
  103. {:@abstract(Exception clas used by Synapse)
  104. When you enable generating of exceptions, this exception is raised by
  105. Synapse's units.}
  106. ESynapseError = class(Exception)
  107. private
  108. FErrorCode: Integer;
  109. FErrorMessage: string;
  110. published
  111. {:Code of error. Value depending on used operating system}
  112. property ErrorCode: Integer read FErrorCode Write FErrorCode;
  113. {:Human readable description of error.}
  114. property ErrorMessage: string read FErrorMessage Write FErrorMessage;
  115. end;
  116. {:Types of OnStatus events}
  117. THookSocketReason = (
  118. {:Resolving is begin. Resolved IP and port is in parameter in format like:
  119. 'localhost.somewhere.com:25'.}
  120. HR_ResolvingBegin,
  121. {:Resolving is done. Resolved IP and port is in parameter in format like:
  122. 'localhost.somewhere.com:25'. It is always same as in HR_ResolvingBegin!}
  123. HR_ResolvingEnd,
  124. {:Socket created by CreateSocket method. It reporting Family of created
  125. socket too!}
  126. HR_SocketCreate,
  127. {:Socket closed by CloseSocket method.}
  128. HR_SocketClose,
  129. {:Socket binded to IP and Port. Binded IP and Port is in parameter in format
  130. like: 'localhost.somewhere.com:25'.}
  131. HR_Bind,
  132. {:Socket connected to IP and Port. Connected IP and Port is in parameter in
  133. format like: 'localhost.somewhere.com:25'.}
  134. HR_Connect,
  135. {:Called when CanRead method is used with @True result.}
  136. HR_CanRead,
  137. {:Called when CanWrite method is used with @True result.}
  138. HR_CanWrite,
  139. {:Socket is swithed to Listen mode. (TCP socket only)}
  140. HR_Listen,
  141. {:Socket Accepting client connection. (TCP socket only)}
  142. HR_Accept,
  143. {:report count of bytes readed from socket. Number is in parameter string.
  144. If you need is in integer, you must use StrToInt function!}
  145. HR_ReadCount,
  146. {:report count of bytes writed to socket. Number is in parameter string. If
  147. you need is in integer, you must use StrToInt function!}
  148. HR_WriteCount,
  149. {:If is limiting of bandwidth on, then this reason is called when sending or
  150. receiving is stopped for satisfy bandwidth limit. Parameter is count of
  151. waiting milliseconds.}
  152. HR_Wait,
  153. {:report situation where communication error occured. When raiseexcept is
  154. @true, then exception is called after this Hook reason.}
  155. HR_Error
  156. );
  157. {:Procedural type for OnStatus event. Sender is calling TBlockSocket object,
  158. Reason is one of set Status events and value is optional data.}
  159. THookSocketStatus = procedure(Sender: TObject; Reason: THookSocketReason;
  160. const Value: String) of object;
  161. {:This procedural type is used for DataFilter hooks.}
  162. THookDataFilter = procedure(Sender: TObject; var Value: AnsiString) of object;
  163. {:This procedural type is used for hook OnCreateSocket. By this hook you can
  164. insert your code after initialisation of socket. (you can set special socket
  165. options, etc.)}
  166. THookCreateSocket = procedure(Sender: TObject) of object;
  167. {:This procedural type is used for monitoring of communication.}
  168. THookMonitor = procedure(Sender: TObject; Writing: Boolean;
  169. const Buffer: TMemory; Len: Integer) of object;
  170. {:This procedural type is used for hook OnAfterConnect. By this hook you can
  171. insert your code after TCP socket has been sucessfully connected.}
  172. THookAfterConnect = procedure(Sender: TObject) of object;
  173. {:This procedural type is used for hook OnHeartbeat. By this hook you can
  174. call your code repeately during long socket operations.
  175. You must enable heartbeats by @Link(HeartbeatRate) property!}
  176. THookHeartbeat = procedure(Sender: TObject) of object;
  177. {:Specify family of socket.}
  178. TSocketFamily = (
  179. {:Default mode. Socket family is defined by target address for connection.
  180. It allows instant access to IPv4 and IPv6 nodes. When you need IPv6 address
  181. as destination, then is used IPv6 mode. othervise is used IPv4 mode.
  182. However this mode not working properly with preliminary IPv6 supports!}
  183. SF_Any,
  184. {:Turn this class to pure IPv4 mode. This mode is totally compatible with
  185. previous Synapse releases.}
  186. SF_IP4,
  187. {:Turn to only IPv6 mode.}
  188. SF_IP6
  189. );
  190. {:specify possible values of SOCKS modes.}
  191. TSocksType = (
  192. ST_Socks5,
  193. ST_Socks4
  194. );
  195. {:Specify requested SSL/TLS version for secure connection.}
  196. TSSLType = (
  197. LT_all,
  198. LT_SSLv2,
  199. LT_SSLv3,
  200. LT_TLSv1,
  201. LT_TLSv1_1,
  202. LT_SSHv2
  203. );
  204. {:Specify type of socket delayed option.}
  205. TSynaOptionType = (
  206. SOT_Linger,
  207. SOT_RecvBuff,
  208. SOT_SendBuff,
  209. SOT_NonBlock,
  210. SOT_RecvTimeout,
  211. SOT_SendTimeout,
  212. SOT_Reuse,
  213. SOT_TTL,
  214. SOT_Broadcast,
  215. SOT_MulticastTTL,
  216. SOT_MulticastLoop
  217. );
  218. {:@abstract(this object is used for remember delayed socket option set.)}
  219. TSynaOption = class(TObject)
  220. public
  221. Option: TSynaOptionType;
  222. Enabled: Boolean;
  223. Value: Integer;
  224. end;
  225. TCustomSSL = class;
  226. TSSLClass = class of TCustomSSL;
  227. {:@abstract(Basic IP object.)
  228. This is parent class for other class with protocol implementations. Do not
  229. use this class directly! Use @link(TICMPBlockSocket), @link(TRAWBlockSocket),
  230. @link(TTCPBlockSocket) or @link(TUDPBlockSocket) instead.}
  231. TBlockSocket = class(TObject)
  232. private
  233. FOnStatus: THookSocketStatus;
  234. FOnReadFilter: THookDataFilter;
  235. FOnCreateSocket: THookCreateSocket;
  236. FOnMonitor: THookMonitor;
  237. FOnHeartbeat: THookHeartbeat;
  238. FLocalSin: TVarSin;
  239. FRemoteSin: TVarSin;
  240. FTag: integer;
  241. FBuffer: AnsiString;
  242. FRaiseExcept: Boolean;
  243. FNonBlockMode: Boolean;
  244. FMaxLineLength: Integer;
  245. FMaxSendBandwidth: Integer;
  246. FNextSend: LongWord;
  247. FMaxRecvBandwidth: Integer;
  248. FNextRecv: LongWord;
  249. FConvertLineEnd: Boolean;
  250. FLastCR: Boolean;
  251. FLastLF: Boolean;
  252. FBinded: Boolean;
  253. FFamily: TSocketFamily;
  254. FFamilySave: TSocketFamily;
  255. FIP6used: Boolean;
  256. FPreferIP4: Boolean;
  257. FDelayedOptions: TList;
  258. FInterPacketTimeout: Boolean;
  259. {$IFNDEF CIL}
  260. FFDSet: TFDSet;
  261. {$ENDIF}
  262. FRecvCounter: Integer;
  263. FSendCounter: Integer;
  264. FSendMaxChunk: Integer;
  265. FStopFlag: Boolean;
  266. FNonblockSendTimeout: Integer;
  267. FHeartbeatRate: integer;
  268. function GetSizeRecvBuffer: Integer;
  269. procedure SetSizeRecvBuffer(Size: Integer);
  270. function GetSizeSendBuffer: Integer;
  271. procedure SetSizeSendBuffer(Size: Integer);
  272. procedure SetNonBlockMode(Value: Boolean);
  273. procedure SetTTL(TTL: integer);
  274. function GetTTL:integer;
  275. procedure SetFamily(Value: TSocketFamily); virtual;
  276. procedure SetSocket(Value: TSocket); virtual;
  277. function GetWsaData: TWSAData;
  278. function FamilyToAF(f: TSocketFamily): TAddrFamily;
  279. protected
  280. FSocket: TSocket;
  281. FLastError: Integer;
  282. FLastErrorDesc: string;
  283. procedure SetDelayedOption(const Value: TSynaOption);
  284. procedure DelayedOption(const Value: TSynaOption);
  285. procedure ProcessDelayedOptions;
  286. procedure InternalCreateSocket(Sin: TVarSin);
  287. procedure SetSin(var Sin: TVarSin; IP, Port: string);
  288. function GetSinIP(Sin: TVarSin): string;
  289. function GetSinPort(Sin: TVarSin): Integer;
  290. procedure DoStatus(Reason: THookSocketReason; const Value: string);
  291. procedure DoReadFilter(Buffer: TMemory; var Len: Integer);
  292. procedure DoMonitor(Writing: Boolean; const Buffer: TMemory; Len: Integer);
  293. procedure DoCreateSocket;
  294. procedure DoHeartbeat;
  295. procedure LimitBandwidth(Length: Integer; MaxB: integer; var Next: LongWord);
  296. procedure SetBandwidth(Value: Integer);
  297. function TestStopFlag: Boolean;
  298. procedure InternalSendStream(const Stream: TStream; WithSize, Indy: boolean); virtual;
  299. function InternalCanRead(Timeout: Integer): Boolean; virtual;
  300. public
  301. constructor Create;
  302. {:Create object and load all necessary socket library. What library is
  303. loaded is described by STUB parameter. If STUB is empty string, then is
  304. loaded default libraries.}
  305. constructor CreateAlternate(Stub: string);
  306. destructor Destroy; override;
  307. {:If @link(family) is not SF_Any, then create socket with type defined in
  308. @link(Family) property. If family is SF_Any, then do nothing! (socket is
  309. created automaticly when you know what type of socket you need to create.
  310. (i.e. inside @link(Connect) or @link(Bind) call.) When socket is created,
  311. then is aplyed all stored delayed socket options.}
  312. procedure CreateSocket;
  313. {:It create socket. Address resolving of Value tells what type of socket is
  314. created. If Value is resolved as IPv4 IP, then is created IPv4 socket. If
  315. value is resolved as IPv6 address, then is created IPv6 socket.}
  316. procedure CreateSocketByName(const Value: String);
  317. {:Destroy socket in use. This method is also automatically called from
  318. object destructor.}
  319. procedure CloseSocket; virtual;
  320. {:Abort any work on Socket and destroy them.}
  321. procedure AbortSocket; virtual;
  322. {:Connects socket to local IP address and PORT. IP address may be numeric or
  323. symbolic ('192.168.74.50', 'cosi.nekde.cz', 'ff08::1'). The same for PORT
  324. - it may be number or mnemonic port ('23', 'telnet').
  325. If port value is '0', system chooses itself and conects unused port in the
  326. range 1024 to 4096 (this depending by operating system!). Structure
  327. LocalSin is filled after calling this method.
  328. Note: If you call this on non-created socket, then socket is created
  329. automaticly.
  330. Warning: when you call : Bind('0.0.0.0','0'); then is nothing done! In this
  331. case is used implicit system bind instead.}
  332. procedure Bind(IP, Port: string);
  333. {:Connects socket to remote IP address and PORT. The same rules as with
  334. @link(BIND) method are valid. The only exception is that PORT with 0 value
  335. will not be connected!
  336. Structures LocalSin and RemoteSin will be filled with valid values.
  337. When you call this on non-created socket, then socket is created
  338. automaticly. Type of created socket is by @link(Family) property. If is
  339. used SF_IP4, then is created socket for IPv4. If is used SF_IP6, then is
  340. created socket for IPv6. When you have family on SF_Any (default!), then
  341. type of created socket is determined by address resolving of destination
  342. address. (Not work properly on prilimitary winsock IPv6 support!)}
  343. procedure Connect(IP, Port: string); virtual;
  344. {:Sends data of LENGTH from BUFFER address via connected socket. System
  345. automatically splits data to packets.}
  346. function SendBuffer(Buffer: Tmemory; Length: Integer): Integer; virtual;
  347. {:One data BYTE is sent via connected socket.}
  348. procedure SendByte(Data: Byte); virtual;
  349. {:Send data string via connected socket. Any terminator is not added! If you
  350. need send true string with CR-LF termination, you must add CR-LF characters
  351. to sended string! Because any termination is not added automaticly, you can
  352. use this function for sending any binary data in binary string.}
  353. procedure SendString(Data: AnsiString); virtual;
  354. {:Send integer as four bytes to socket.}
  355. procedure SendInteger(Data: integer); virtual;
  356. {:Send data as one block to socket. Each block begin with 4 bytes with
  357. length of data in block. This 4 bytes is added automaticly by this
  358. function.}
  359. procedure SendBlock(const Data: AnsiString); virtual;
  360. {:Send data from stream to socket.}
  361. procedure SendStreamRaw(const Stream: TStream); virtual;
  362. {:Send content of stream to socket. It using @link(SendBlock) method}
  363. procedure SendStream(const Stream: TStream); virtual;
  364. {:Send content of stream to socket. It using @link(SendBlock) method and
  365. this is compatible with streams in Indy library.}
  366. procedure SendStreamIndy(const Stream: TStream); virtual;
  367. {:Note: This is low-level receive function. You must be sure if data is
  368. waiting for read before call this function for avoid deadlock!
  369. Waits until allocated buffer is filled by received data. Returns number of
  370. data received, which equals to LENGTH value under normal operation. If it
  371. is not equal the communication channel is possibly broken.
  372. On stream oriented sockets if is received 0 bytes, it mean 'socket is
  373. closed!"
  374. On datagram socket is readed first waiting datagram.}
  375. function RecvBuffer(Buffer: TMemory; Length: Integer): Integer; virtual;
  376. {:Note: This is high-level receive function. It using internal
  377. @link(LineBuffer) and you can combine this function freely with other
  378. high-level functions!
  379. Method waits until data is received. If no data is received within TIMEOUT
  380. (in milliseconds) period, @link(LastError) is set to WSAETIMEDOUT. Methods
  381. serves for reading any size of data (i.e. one megabyte...). This method is
  382. preffered for reading from stream sockets (like TCP).}
  383. function RecvBufferEx(Buffer: Tmemory; Len: Integer;
  384. Timeout: Integer): Integer; virtual;
  385. {:Similar to @link(RecvBufferEx), but readed data is stored in binary
  386. string, not in memory buffer.}
  387. function RecvBufferStr(Len: Integer; Timeout: Integer): AnsiString; virtual;
  388. {:Note: This is high-level receive function. It using internal
  389. @link(LineBuffer) and you can combine this function freely with other
  390. high-level functions.
  391. Waits until one data byte is received which is also returned as function
  392. result. If no data is received within TIMEOUT (in milliseconds)period,
  393. @link(LastError) is set to WSAETIMEDOUT and result have value 0.}
  394. function RecvByte(Timeout: Integer): Byte; virtual;
  395. {:Note: This is high-level receive function. It using internal
  396. @link(LineBuffer) and you can combine this function freely with other
  397. high-level functions.
  398. Waits until one four bytes are received and return it as one Ineger Value.
  399. If no data is received within TIMEOUT (in milliseconds)period,
  400. @link(LastError) is set to WSAETIMEDOUT and result have value 0.}
  401. function RecvInteger(Timeout: Integer): Integer; virtual;
  402. {:Note: This is high-level receive function. It using internal
  403. @link(LineBuffer) and you can combine this function freely with other
  404. high-level functions.
  405. Method waits until data string is received. This string is terminated by
  406. CR-LF characters. The resulting string is returned without this termination
  407. (CR-LF)! If @link(ConvertLineEnd) is used, then CR-LF sequence may not be
  408. exactly CR-LF. See @link(ConvertLineEnd) description. If no data is
  409. received within TIMEOUT (in milliseconds) period, @link(LastError) is set
  410. to WSAETIMEDOUT. You may also specify maximum length of reading data by
  411. @link(MaxLineLength) property.}
  412. function RecvString(Timeout: Integer): AnsiString; virtual;
  413. {:Note: This is high-level receive function. It using internal
  414. @link(LineBuffer) and you can combine this function freely with other
  415. high-level functions.
  416. Method waits until data string is received. This string is terminated by
  417. Terminator string. The resulting string is returned without this
  418. termination. If no data is received within TIMEOUT (in milliseconds)
  419. period, @link(LastError) is set to WSAETIMEDOUT. You may also specify
  420. maximum length of reading data by @link(MaxLineLength) property.}
  421. function RecvTerminated(Timeout: Integer; const Terminator: AnsiString): AnsiString; virtual;
  422. {:Note: This is high-level receive function. It using internal
  423. @link(LineBuffer) and you can combine this function freely with other
  424. high-level functions.
  425. Method reads all data waiting for read. If no data is received within
  426. TIMEOUT (in milliseconds) period, @link(LastError) is set to WSAETIMEDOUT.
  427. Methods serves for reading unknown size of data. Because before call this
  428. function you don't know size of received data, returned data is stored in
  429. dynamic size binary string. This method is preffered for reading from
  430. stream sockets (like TCP). It is very goot for receiving datagrams too!
  431. (UDP protocol)}
  432. function RecvPacket(Timeout: Integer): AnsiString; virtual;
  433. {:Read one block of data from socket. Each block begin with 4 bytes with
  434. length of data in block. This function read first 4 bytes for get lenght,
  435. then it wait for reported count of bytes.}
  436. function RecvBlock(Timeout: Integer): AnsiString; virtual;
  437. {:Read all data from socket to stream until socket is closed (or any error
  438. occured.)}
  439. procedure RecvStreamRaw(const Stream: TStream; Timeout: Integer); virtual;
  440. {:Read requested count of bytes from socket to stream.}
  441. procedure RecvStreamSize(const Stream: TStream; Timeout: Integer; Size: Integer);
  442. {:Receive data to stream. It using @link(RecvBlock) method.}
  443. procedure RecvStream(const Stream: TStream; Timeout: Integer); virtual;
  444. {:Receive data to stream. This function is compatible with similar function
  445. in Indy library. It using @link(RecvBlock) method.}
  446. procedure RecvStreamIndy(const Stream: TStream; Timeout: Integer); virtual;
  447. {:Same as @link(RecvBuffer), but readed data stays in system input buffer.
  448. Warning: this function not respect data in @link(LineBuffer)! Is not
  449. recommended to use this function!}
  450. function PeekBuffer(Buffer: TMemory; Length: Integer): Integer; virtual;
  451. {:Same as @link(RecvByte), but readed data stays in input system buffer.
  452. Warning: this function not respect data in @link(LineBuffer)! Is not
  453. recommended to use this function!}
  454. function PeekByte(Timeout: Integer): Byte; virtual;
  455. {:On stream sockets it returns number of received bytes waiting for picking.
  456. 0 is returned when there is no such data. On datagram socket it returns
  457. length of the first waiting datagram. Returns 0 if no datagram is waiting.}
  458. function WaitingData: Integer; virtual;
  459. {:Same as @link(WaitingData), but if exists some of data in @link(Linebuffer),
  460. return their length instead.}
  461. function WaitingDataEx: Integer;
  462. {:Clear all waiting data for read from buffers.}
  463. procedure Purge;
  464. {:Sets linger. Enabled linger means that the system waits another LINGER
  465. (in milliseconds) time for delivery of sent data. This function is only for
  466. stream type of socket! (TCP)}
  467. procedure SetLinger(Enable: Boolean; Linger: Integer);
  468. {:Actualize values in @link(LocalSin).}
  469. procedure GetSinLocal;
  470. {:Actualize values in @link(RemoteSin).}
  471. procedure GetSinRemote;
  472. {:Actualize values in @link(LocalSin) and @link(RemoteSin).}
  473. procedure GetSins;
  474. {:Reset @link(LastError) and @link(LastErrorDesc) to non-error state.}
  475. procedure ResetLastError;
  476. {:If you "manually" call Socket API functions, forward their return code as
  477. parameter to this function, which evaluates it, eventually calls
  478. GetLastError and found error code returns and stores to @link(LastError).}
  479. function SockCheck(SockResult: Integer): Integer; virtual;
  480. {:If @link(LastError) contains some error code and @link(RaiseExcept)
  481. property is @true, raise adequate exception.}
  482. procedure ExceptCheck;
  483. {:Returns local computer name as numerical or symbolic value. It try get
  484. fully qualified domain name. Name is returned in the format acceptable by
  485. functions demanding IP as input parameter.}
  486. function LocalName: string;
  487. {:Try resolve name to all possible IP address. i.e. If you pass as name
  488. result of @link(LocalName) method, you get all IP addresses used by local
  489. system.}
  490. procedure ResolveNameToIP(Name: string; const IPList: TStrings);
  491. {:Try resolve name to primary IP address. i.e. If you pass as name result of
  492. @link(LocalName) method, you get primary IP addresses used by local system.}
  493. function ResolveName(Name: string): string;
  494. {:Try resolve IP to their primary domain name. If IP not have domain name,
  495. then is returned original IP.}
  496. function ResolveIPToName(IP: string): string;
  497. {:Try resolve symbolic port name to port number. (i.e. 'Echo' to 8)}
  498. function ResolvePort(Port: string): Word;
  499. {:Set information about remote side socket. It is good for seting remote
  500. side for sending UDP packet, etc.}
  501. procedure SetRemoteSin(IP, Port: string);
  502. {:Picks IP socket address from @link(LocalSin).}
  503. function GetLocalSinIP: string; virtual;
  504. {:Picks IP socket address from @link(RemoteSin).}
  505. function GetRemoteSinIP: string; virtual;
  506. {:Picks socket PORT number from @link(LocalSin).}
  507. function GetLocalSinPort: Integer; virtual;
  508. {:Picks socket PORT number from @link(RemoteSin).}
  509. function GetRemoteSinPort: Integer; virtual;
  510. {:Return @TRUE, if you can read any data from socket or is incoming
  511. connection on TCP based socket. Status is tested for time Timeout (in
  512. milliseconds). If value in Timeout is 0, status is only tested and
  513. continue. If value in Timeout is -1, run is breaked and waiting for read
  514. data maybe forever.
  515. This function is need only on special cases, when you need use
  516. @link(RecvBuffer) function directly! read functioms what have timeout as
  517. calling parameter, calling this function internally.}
  518. function CanRead(Timeout: Integer): Boolean; virtual;
  519. {:Same as @link(CanRead), but additionally return @TRUE if is some data in
  520. @link(LineBuffer).}
  521. function CanReadEx(Timeout: Integer): Boolean; virtual;
  522. {:Return @TRUE, if you can to socket write any data (not full sending
  523. buffer). Status is tested for time Timeout (in milliseconds). If value in
  524. Timeout is 0, status is only tested and continue. If value in Timeout is
  525. -1, run is breaked and waiting for write data maybe forever.
  526. This function is need only on special cases!}
  527. function CanWrite(Timeout: Integer): Boolean; virtual;
  528. {:Same as @link(SendBuffer), but send datagram to address from
  529. @link(RemoteSin). Usefull for sending reply to datagram received by
  530. function @link(RecvBufferFrom).}
  531. function SendBufferTo(Buffer: TMemory; Length: Integer): Integer; virtual;
  532. {:Note: This is low-lever receive function. You must be sure if data is
  533. waiting for read before call this function for avoid deadlock!
  534. Receives first waiting datagram to allocated buffer. If there is no waiting
  535. one, then waits until one comes. Returns length of datagram stored in
  536. BUFFER. If length exceeds buffer datagram is truncated. After this
  537. @link(RemoteSin) structure contains information about sender of UDP packet.}
  538. function RecvBufferFrom(Buffer: TMemory; Length: Integer): Integer; virtual;
  539. {$IFNDEF CIL}
  540. {:This function is for check for incoming data on set of sockets. Whitch
  541. sockets is checked is decribed by SocketList Tlist with TBlockSocket
  542. objects. TList may have maximal number of objects defined by FD_SETSIZE
  543. constant. Return @TRUE, if you can from some socket read any data or is
  544. incoming connection on TCP based socket. Status is tested for time Timeout
  545. (in milliseconds). If value in Timeout is 0, status is only tested and
  546. continue. If value in Timeout is -1, run is breaked and waiting for read
  547. data maybe forever. If is returned @TRUE, CanReadList TList is filled by all
  548. TBlockSocket objects what waiting for read.}
  549. function GroupCanRead(const SocketList: TList; Timeout: Integer;
  550. const CanReadList: TList): Boolean;
  551. {$ENDIF}
  552. {:By this method you may turn address reuse mode for local @link(bind). It
  553. is good specially for UDP protocol. Using this with TCP protocol is
  554. hazardous!}
  555. procedure EnableReuse(Value: Boolean);
  556. {:Try set timeout for all sending and receiving operations, if socket
  557. provider can do it. (It not supported by all socket providers!)}
  558. procedure SetTimeout(Timeout: Integer);
  559. {:Try set timeout for all sending operations, if socket provider can do it.
  560. (It not supported by all socket providers!)}
  561. procedure SetSendTimeout(Timeout: Integer);
  562. {:Try set timeout for all receiving operations, if socket provider can do
  563. it. (It not supported by all socket providers!)}
  564. procedure SetRecvTimeout(Timeout: Integer);
  565. {:Return value of socket type.}
  566. function GetSocketType: integer; Virtual;
  567. {:Return value of protocol type for socket creation.}
  568. function GetSocketProtocol: integer; Virtual;
  569. {:WSA structure with information about socket provider. On linux is this
  570. structure simulated!}
  571. property WSAData: TWSADATA read GetWsaData;
  572. {:Structure describing local socket side.}
  573. property LocalSin: TVarSin read FLocalSin write FLocalSin;
  574. {:Structure describing remote socket side.}
  575. property RemoteSin: TVarSin read FRemoteSin write FRemoteSin;
  576. {:Socket handler. Suitable for "manual" calls to socket API or manual
  577. connection of socket to a previously created socket (i.e by Accept method
  578. on TCP socket)}
  579. property Socket: TSocket read FSocket write SetSocket;
  580. {:Last socket operation error code. Error codes are described in socket
  581. documentation. Human readable error description is stored in
  582. @link(LastErrorDesc) property.}
  583. property LastError: Integer read FLastError;
  584. {:Human readable error description of @link(LastError) code.}
  585. property LastErrorDesc: string read FLastErrorDesc;
  586. {:Buffer used by all high-level receiving functions. This buffer is used for
  587. optimized reading of data from socket. In normal cases you not need access
  588. to this buffer directly!}
  589. property LineBuffer: AnsiString read FBuffer write FBuffer;
  590. {:Size of Winsock receive buffer. If it is not supported by socket provider,
  591. it return as size one kilobyte.}
  592. property SizeRecvBuffer: Integer read GetSizeRecvBuffer write SetSizeRecvBuffer;
  593. {:Size of Winsock send buffer. If it is not supported by socket provider, it
  594. return as size one kilobyte.}
  595. property SizeSendBuffer: Integer read GetSizeSendBuffer write SetSizeSendBuffer;
  596. {:If @True, turn class to non-blocking mode. Not all functions are working
  597. properly in this mode, you must know exactly what you are doing! However
  598. when you have big experience with non-blocking programming, then you can
  599. optimise your program by non-block mode!}
  600. property NonBlockMode: Boolean read FNonBlockMode Write SetNonBlockMode;
  601. {:Set Time-to-live value. (if system supporting it!)}
  602. property TTL: Integer read GetTTL Write SetTTL;
  603. {:If is @true, then class in in IPv6 mode.}
  604. property IP6used: Boolean read FIP6used;
  605. {:Return count of received bytes on this socket from begin of current
  606. connection.}
  607. property RecvCounter: Integer read FRecvCounter;
  608. {:Return count of sended bytes on this socket from begin of current
  609. connection.}
  610. property SendCounter: Integer read FSendCounter;
  611. published
  612. {:Return descriptive string for given error code. This is class function.
  613. You may call it without created object!}
  614. class function GetErrorDesc(ErrorCode: Integer): string;
  615. {:Return descriptive string for @link(LastError).}
  616. function GetErrorDescEx: string; virtual;
  617. {:this value is for free use.}
  618. property Tag: Integer read FTag write FTag;
  619. {:If @true, winsock errors raises exception. Otherwise is setted
  620. @link(LastError) value only and you must check it from your program! Default
  621. value is @false.}
  622. property RaiseExcept: Boolean read FRaiseExcept write FRaiseExcept;
  623. {:Define maximum length in bytes of @link(LineBuffer) for high-level
  624. receiving functions. If this functions try to read more data then this
  625. limit, error is returned! If value is 0 (default), no limitation is used.
  626. This is very good protection for stupid attacks to your server by sending
  627. lot of data without proper terminator... until all your memory is allocated
  628. by LineBuffer!
  629. Note: This maximum length is checked only in functions, what read unknown
  630. number of bytes! (like @link(RecvString) or @link(RecvTerminated))}
  631. property MaxLineLength: Integer read FMaxLineLength Write FMaxLineLength;
  632. {:Define maximal bandwidth for all sending operations in bytes per second.
  633. If value is 0 (default), bandwidth limitation is not used.}
  634. property MaxSendBandwidth: Integer read FMaxSendBandwidth Write FMaxSendBandwidth;
  635. {:Define maximal bandwidth for all receiving operations in bytes per second.
  636. If value is 0 (default), bandwidth limitation is not used.}
  637. property MaxRecvBandwidth: Integer read FMaxRecvBandwidth Write FMaxRecvBandwidth;
  638. {:Define maximal bandwidth for all sending and receiving operations in bytes
  639. per second. If value is 0 (default), bandwidth limitation is not used.}
  640. property MaxBandwidth: Integer Write SetBandwidth;
  641. {:Do a conversion of non-standard line terminators to CRLF. (Off by default)
  642. If @True, then terminators like sigle CR, single LF or LFCR are converted
  643. to CRLF internally. This have effect only in @link(RecvString) method!}
  644. property ConvertLineEnd: Boolean read FConvertLineEnd Write FConvertLineEnd;
  645. {:Specified Family of this socket. When you are using Windows preliminary
  646. support for IPv6, then I recommend to set this property!}
  647. property Family: TSocketFamily read FFamily Write SetFamily;
  648. {:When resolving of domain name return both IPv4 and IPv6 addresses, then
  649. specify if is used IPv4 (dafault - @true) or IPv6.}
  650. property PreferIP4: Boolean read FPreferIP4 Write FPreferIP4;
  651. {:By default (@true) is all timeouts used as timeout between two packets in
  652. reading operations. If you set this to @false, then Timeouts is for overall
  653. reading operation!}
  654. property InterPacketTimeout: Boolean read FInterPacketTimeout Write FInterPacketTimeout;
  655. {:All sended datas was splitted by this value.}
  656. property SendMaxChunk: Integer read FSendMaxChunk Write FSendMaxChunk;
  657. {:By setting this property to @true you can stop any communication. You can
  658. use this property for soft abort of communication.}
  659. property StopFlag: Boolean read FStopFlag Write FStopFlag;
  660. {:Timeout for data sending by non-blocking socket mode.}
  661. property NonblockSendTimeout: Integer read FNonblockSendTimeout Write FNonblockSendTimeout;
  662. {:This event is called by various reasons. It is good for monitoring socket,
  663. create gauges for data transfers, etc.}
  664. property OnStatus: THookSocketStatus read FOnStatus write FOnStatus;
  665. {:this event is good for some internal thinks about filtering readed datas.
  666. It is used by telnet client by example.}
  667. property OnReadFilter: THookDataFilter read FOnReadFilter write FOnReadFilter;
  668. {:This event is called after real socket creation for setting special socket
  669. options, because you not know when socket is created. (it is depended on
  670. Ipv4, IPv6 or automatic mode)}
  671. property OnCreateSocket: THookCreateSocket read FOnCreateSocket write FOnCreateSocket;
  672. {:This event is good for monitoring content of readed or writed datas.}
  673. property OnMonitor: THookMonitor read FOnMonitor write FOnMonitor;
  674. {:This event is good for calling your code during long socket operations.
  675. (Example, for refresing UI if class in not called within the thread.)
  676. Rate of heartbeats can be modified by @link(HeartbeatRate) property.}
  677. property OnHeartbeat: THookHeartbeat read FOnHeartbeat write FOnHeartbeat;
  678. {:Specify typical rate of @link(OnHeartbeat) event and @link(StopFlag) testing.
  679. Default value 0 disabling heartbeats! Value is in milliseconds.
  680. Real rate can be higher or smaller then this value, because it depending
  681. on real socket operations too!
  682. Note: Each heartbeat slowing socket processing.}
  683. property HeartbeatRate: integer read FHeartbeatRate Write FHeartbeatRate;
  684. end;
  685. {:@abstract(Support for SOCKS4 and SOCKS5 proxy)
  686. Layer with definition all necessary properties and functions for
  687. implementation SOCKS proxy client. Do not use this class directly.}
  688. TSocksBlockSocket = class(TBlockSocket)
  689. protected
  690. FSocksIP: string;
  691. FSocksPort: string;
  692. FSocksTimeout: integer;
  693. FSocksUsername: string;
  694. FSocksPassword: string;
  695. FUsingSocks: Boolean;
  696. FSocksResolver: Boolean;
  697. FSocksLastError: integer;
  698. FSocksResponseIP: string;
  699. FSocksResponsePort: string;
  700. FSocksLocalIP: string;
  701. FSocksLocalPort: string;
  702. FSocksRemoteIP: string;
  703. FSocksRemotePort: string;
  704. FBypassFlag: Boolean;
  705. FSocksType: TSocksType;
  706. function SocksCode(IP, Port: string): Ansistring;
  707. function SocksDecode(Value: Ansistring): integer;
  708. public
  709. constructor Create;
  710. {:Open connection to SOCKS proxy and if @link(SocksUsername) is set, do
  711. authorisation to proxy. This is needed only in special cases! (it is called
  712. internally!)}
  713. function SocksOpen: Boolean;
  714. {:Send specified request to SOCKS proxy. This is needed only in special
  715. cases! (it is called internally!)}
  716. function SocksRequest(Cmd: Byte; const IP, Port: string): Boolean;
  717. {:Receive response to previosly sended request. This is needed only in
  718. special cases! (it is called internally!)}
  719. function SocksResponse: Boolean;
  720. {:Is @True when class is using SOCKS proxy.}
  721. property UsingSocks: Boolean read FUsingSocks;
  722. {:If SOCKS proxy failed, here is error code returned from SOCKS proxy.}
  723. property SocksLastError: integer read FSocksLastError;
  724. published
  725. {:Address of SOCKS server. If value is empty string, SOCKS support is
  726. disabled. Assingning any value to this property enable SOCKS mode.
  727. Warning: You cannot combine this mode with HTTP-tunneling mode!}
  728. property SocksIP: string read FSocksIP write FSocksIP;
  729. {:Port of SOCKS server. Default value is '1080'.}
  730. property SocksPort: string read FSocksPort write FSocksPort;
  731. {:If you need authorisation on SOCKS server, set username here.}
  732. property SocksUsername: string read FSocksUsername write FSocksUsername;
  733. {:If you need authorisation on SOCKS server, set password here.}
  734. property SocksPassword: string read FSocksPassword write FSocksPassword;
  735. {:Specify timeout for communicatin with SOCKS server. Default is one minute.}
  736. property SocksTimeout: integer read FSocksTimeout write FSocksTimeout;
  737. {:If @True, all symbolic names of target hosts is not translated to IP's
  738. locally, but resolving is by SOCKS proxy. Default is @True.}
  739. property SocksResolver: Boolean read FSocksResolver write FSocksResolver;
  740. {:Specify SOCKS type. By default is used SOCKS5, but you can use SOCKS4 too.
  741. When you select SOCKS4, then if @link(SOCKSResolver) is enabled, then is
  742. used SOCKS4a. Othervise is used pure SOCKS4.}
  743. property SocksType: TSocksType read FSocksType write FSocksType;
  744. end;
  745. {:@abstract(Implementation of TCP socket.)
  746. Supported features: IPv4, IPv6, SSL/TLS or SSH (depending on used plugin),
  747. SOCKS5 proxy (outgoing connections and limited incomming), SOCKS4/4a proxy
  748. (outgoing connections and limited incomming), TCP through HTTP proxy tunnel.}
  749. TTCPBlockSocket = class(TSocksBlockSocket)
  750. protected
  751. FOnAfterConnect: THookAfterConnect;
  752. FSSL: TCustomSSL;
  753. FHTTPTunnelIP: string;
  754. FHTTPTunnelPort: string;
  755. FHTTPTunnel: Boolean;
  756. FHTTPTunnelRemoteIP: string;
  757. FHTTPTunnelRemotePort: string;
  758. FHTTPTunnelUser: string;
  759. FHTTPTunnelPass: string;
  760. FHTTPTunnelTimeout: integer;
  761. procedure SocksDoConnect(IP, Port: string);
  762. procedure HTTPTunnelDoConnect(IP, Port: string);
  763. procedure DoAfterConnect;
  764. public
  765. {:Create TCP socket class with default plugin for SSL/TSL/SSH implementation
  766. (see @link(SSLImplementation))}
  767. constructor Create;
  768. {:Create TCP socket class with desired plugin for SSL/TSL/SSH implementation}
  769. constructor CreateWithSSL(SSLPlugin: TSSLClass);
  770. destructor Destroy; override;
  771. {:Return descriptive string for @link(LastError). On case of error
  772. in SSL/TLS subsystem, it returns right error description.}
  773. function GetErrorDescEx: string; override;
  774. {:See @link(TBlockSocket.CloseSocket)}
  775. procedure CloseSocket; override;
  776. {:See @link(TBlockSocket.WaitingData)}
  777. function WaitingData: Integer; override;
  778. {:Sets socket to receive mode for new incoming connections. It is necessary
  779. to use @link(TBlockSocket.BIND) function call before this method to select
  780. receiving port!
  781. If you use SOCKS, activate incoming TCP connection by this proxy. (By BIND
  782. method of SOCKS.)}
  783. procedure Listen; virtual;
  784. {:Waits until new incoming connection comes. After it comes a new socket is
  785. automatically created (socket handler is returned by this function as
  786. result).
  787. If you use SOCKS, new socket is not created! In this case is used same
  788. socket as socket for listening! So, you can accept only one connection in
  789. SOCKS mode.}
  790. function Accept: TSocket;
  791. {:Connects socket to remote IP address and PORT. The same rules as with
  792. @link(TBlockSocket.BIND) method are valid. The only exception is that PORT
  793. with 0 value will not be connected. After call to this method
  794. a communication channel between local and remote socket is created. Local
  795. socket is assigned automatically if not controlled by previous call to
  796. @link(TBlockSocket.BIND) method. Structures @link(TBlockSocket.LocalSin)
  797. and @link(TBlockSocket.RemoteSin) will be filled with valid values.
  798. If you use SOCKS, activate outgoing TCP connection by SOCKS proxy specified
  799. in @link(TSocksBlockSocket.SocksIP). (By CONNECT method of SOCKS.)
  800. If you use HTTP-tunnel mode, activate outgoing TCP connection by HTTP
  801. tunnel specified in @link(HTTPTunnelIP). (By CONNECT method of HTTP
  802. protocol.)
  803. Note: If you call this on non-created socket, then socket is created
  804. automaticly.}
  805. procedure Connect(IP, Port: string); override;
  806. {:If you need upgrade existing TCP connection to SSL/TLS (or SSH2, if plugin
  807. allows it) mode, then call this method. This method switch this class to
  808. SSL mode and do SSL/TSL handshake.}
  809. procedure SSLDoConnect;
  810. {:By this method you can downgrade existing SSL/TLS connection to normal TCP
  811. connection.}
  812. procedure SSLDoShutdown;
  813. {:If you need use this component as SSL/TLS TCP server, then after accepting
  814. of inbound connection you need start SSL/TLS session by this method. Before
  815. call this function, you must have assigned all neeeded certificates and
  816. keys!}
  817. function SSLAcceptConnection: Boolean;
  818. {:See @link(TBlockSocket.GetLocalSinIP)}
  819. function GetLocalSinIP: string; override;
  820. {:See @link(TBlockSocket.GetRemoteSinIP)}
  821. function GetRemoteSinIP: string; override;
  822. {:See @link(TBlockSocket.GetLocalSinPort)}
  823. function GetLocalSinPort: Integer; override;
  824. {:See @link(TBlockSocket.GetRemoteSinPort)}
  825. function GetRemoteSinPort: Integer; override;
  826. {:See @link(TBlockSocket.SendBuffer)}
  827. function SendBuffer(Buffer: TMemory; Length: Integer): Integer; override;
  828. {:See @link(TBlockSocket.RecvBuffer)}
  829. function RecvBuffer(Buffer: TMemory; Len: Integer): Integer; override;
  830. {:Return value of socket type. For TCP return SOCK_STREAM.}
  831. function GetSocketType: integer; override;
  832. {:Return value of protocol type for socket creation. For TCP return
  833. IPPROTO_TCP.}
  834. function GetSocketProtocol: integer; override;
  835. {:Class implementing SSL/TLS support. It is allways some descendant
  836. of @link(TCustomSSL) class. When programmer not select some SSL plugin
  837. class, then is used @link(TSSLNone)}
  838. property SSL: TCustomSSL read FSSL;
  839. {:@True if is used HTTP tunnel mode.}
  840. property HTTPTunnel: Boolean read FHTTPTunnel;
  841. published
  842. {:Specify IP address of HTTP proxy. Assingning non-empty value to this
  843. property enable HTTP-tunnel mode. This mode is for tunnelling any outgoing
  844. TCP connection through HTTP proxy server. (If policy on HTTP proxy server
  845. allow this!) Warning: You cannot combine this mode with SOCK5 mode!}
  846. property HTTPTunnelIP: string read FHTTPTunnelIP Write FHTTPTunnelIP;
  847. {:Specify port of HTTP proxy for HTTP-tunneling.}
  848. property HTTPTunnelPort: string read FHTTPTunnelPort Write FHTTPTunnelPort;
  849. {:Specify authorisation username for access to HTTP proxy in HTTP-tunnel
  850. mode. If you not need authorisation, then let this property empty.}
  851. property HTTPTunnelUser: string read FHTTPTunnelUser Write FHTTPTunnelUser;
  852. {:Specify authorisation password for access to HTTP proxy in HTTP-tunnel
  853. mode.}
  854. property HTTPTunnelPass: string read FHTTPTunnelPass Write FHTTPTunnelPass;
  855. {:Specify timeout for communication with HTTP proxy in HTTPtunnel mode.}
  856. property HTTPTunnelTimeout: integer read FHTTPTunnelTimeout Write FHTTPTunnelTimeout;
  857. {:This event is called after sucessful TCP socket connection.}
  858. property OnAfterConnect: THookAfterConnect read FOnAfterConnect write FOnAfterConnect;
  859. end;
  860. {:@abstract(Datagram based communication)
  861. This class implementing datagram based communication instead default stream
  862. based communication style.}
  863. TDgramBlockSocket = class(TSocksBlockSocket)
  864. public
  865. {:Fill @link(TBlockSocket.RemoteSin) structure. This address is used for
  866. sending data.}
  867. procedure Connect(IP, Port: string); override;
  868. {:Silently redirected to @link(TBlockSocket.SendBufferTo).}
  869. function SendBuffer(Buffer: TMemory; Length: Integer): Integer; override;
  870. {:Silently redirected to @link(TBlockSocket.RecvBufferFrom).}
  871. function RecvBuffer(Buffer: TMemory; Length: Integer): Integer; override;
  872. end;
  873. {:@abstract(Implementation of UDP socket.)
  874. NOTE: in this class is all receiving redirected to RecvBufferFrom. You can
  875. use for reading any receive function. Preffered is RecvPacket! Similary all
  876. sending is redirected to SendbufferTo. You can use for sending UDP packet any
  877. sending function, like SendString.
  878. Supported features: IPv4, IPv6, unicasts, broadcasts, multicasts, SOCKS5
  879. proxy (only unicasts! Outgoing and incomming.)}
  880. TUDPBlockSocket = class(TDgramBlockSocket)
  881. protected
  882. FSocksControlSock: TTCPBlockSocket;
  883. function UdpAssociation: Boolean;
  884. procedure SetMulticastTTL(TTL: integer);
  885. function GetMulticastTTL:integer;
  886. public
  887. destructor Destroy; override;
  888. {:Enable or disable sending of broadcasts. If seting OK, result is @true.
  889. This method is not supported in SOCKS5 mode! IPv6 does not support
  890. broadcasts! In this case you must use Multicasts instead.}
  891. procedure EnableBroadcast(Value: Boolean);
  892. {:See @link(TBlockSocket.SendBufferTo)}
  893. function SendBufferTo(Buffer: TMemory; Length: Integer): Integer; override;
  894. {:See @link(TBlockSocket.RecvBufferFrom)}
  895. function RecvBufferFrom(Buffer: TMemory; Length: Integer): Integer; override;
  896. {$IFNDEF CIL}
  897. {:Add this socket to given multicast group. You cannot use Multicasts in
  898. SOCKS mode!}
  899. procedure AddMulticast(MCastIP:string);
  900. {:Remove this socket from given multicast group.}
  901. procedure DropMulticast(MCastIP:string);
  902. {$ENDIF}
  903. {:All sended multicast datagrams is loopbacked to your interface too. (you
  904. can read your sended datas.) You can disable this feature by this function.
  905. This function not working on some Windows systems!}
  906. procedure EnableMulticastLoop(Value: Boolean);
  907. {:Return value of socket type. For UDP return SOCK_DGRAM.}
  908. function GetSocketType: integer; override;
  909. {:Return value of protocol type for socket creation. For UDP return
  910. IPPROTO_UDP.}
  911. function GetSocketProtocol: integer; override;
  912. {:Set Time-to-live value for multicasts packets. It define number of routers
  913. for transfer of datas. If you set this to 1 (dafault s

Large files files are truncated, but you can click here to view the full file