Sdk.cs 146 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Runtime.InteropServices;
  6. using System.Text;
  7. using HPSocketCS;
  8. namespace HPSocketCS
  9. {
  10. public interface IServer
  11. {
  12. }
  13. public class ServerEvent
  14. {
  15. public delegate HandleResult OnSendEventHandler(IServer sender, IntPtr connId, byte[] bytes);
  16. public delegate HandleResult OnReceiveEventHandler(IServer sender, IntPtr connId, byte[] bytes);
  17. public delegate HandleResult OnPointerDataReceiveEventHandler(IServer sender, IntPtr connId, IntPtr pData, int length);
  18. public delegate HandleResult OnCloseEventHandler(IServer sender, IntPtr connId, SocketOperation enOperation, int errorCode);
  19. public delegate HandleResult OnShutdownEventHandler(IServer sender);
  20. public delegate HandleResult OnPrepareListenEventHandler(IServer sender, IntPtr soListen);
  21. /// <summary>
  22. /// 连接进入
  23. /// </summary>
  24. /// <param name="sender"></param>
  25. /// <param name="connId"></param>
  26. /// <param name="pClient">如果为 TCP 连接,pClient为 SOCKET 句柄;如果为 UDP 连接,pClient为 SOCKADDR 指针;</param>
  27. /// <returns></returns>
  28. public delegate HandleResult OnAcceptEventHandler(IServer sender, IntPtr connId, IntPtr pClient);
  29. public delegate HandleResult OnHandShakeEventHandler(IServer sender, IntPtr connId);
  30. }
  31. public interface IClient
  32. {
  33. }
  34. public class ClientEvent
  35. {
  36. public delegate HandleResult OnPrepareConnectEventHandler(IClient sender, IntPtr socket);
  37. public delegate HandleResult OnConnectEventHandler(IClient sender);
  38. public delegate HandleResult OnSendEventHandler(IClient sender, byte[] bytes);
  39. public delegate HandleResult OnReceiveEventHandler(IClient sender, byte[] bytes);
  40. public delegate HandleResult OnPointerDataReceiveEventHandler(IClient sender, IntPtr pData, int length);
  41. public delegate HandleResult OnCloseEventHandler(IClient sender, SocketOperation enOperation, int errorCode);
  42. public delegate HandleResult OnHandShakeEventHandler(IClient sender);
  43. }
  44. /// <summary>
  45. /// 通信组件服务状态,用程序可以通过通信组件的 GetState() 方法获取组件当前服务状态
  46. /// </summary>
  47. public enum ServiceState
  48. {
  49. /// <summary>
  50. /// 正在启动
  51. /// </summary>
  52. Starting = 0,
  53. /// <summary>
  54. /// 已经启动
  55. /// </summary>
  56. Started = 1,
  57. /// <summary>
  58. /// 正在停止
  59. /// </summary>
  60. Stopping = 2,
  61. /// <summary>
  62. /// 已经启动
  63. /// </summary>
  64. Stopped = 3,
  65. }
  66. /// <summary>
  67. /// Socket 操作类型,应用程序的 OnErrror() 事件中通过该参数标识是哪种操作导致的错误
  68. /// </summary>
  69. public enum SocketOperation
  70. {
  71. Unknown = 0, // Unknown
  72. Accept = 1, // Accept
  73. Connect = 2, // Connect
  74. Send = 3, // Send
  75. Receive = 4, // Receive
  76. Close = 5, // Receive
  77. };
  78. /// <summary>
  79. /// 事件通知处理结果,事件通知的返回值,不同的返回值会影响通信组件的后续行为
  80. /// </summary>
  81. public enum HandleResult
  82. {
  83. /// <summary>
  84. /// 成功
  85. /// </summary>
  86. Ok = 0,
  87. /// <summary>
  88. /// 忽略
  89. /// </summary>
  90. Ignore = 1,
  91. /// <summary>
  92. /// 错误
  93. /// </summary>
  94. Error = 2,
  95. };
  96. /// <summary>
  97. /// 名称:操作结果代码
  98. /// 描述:组件 Start() / Stop() 方法执行失败时,可通过 GetLastError() 获取错误代码
  99. /// </summary>
  100. public enum SocketError
  101. {
  102. /// <summary>
  103. /// 成功
  104. /// </summary>
  105. Ok = 0,
  106. /// <summary>
  107. /// 当前状态不允许操作
  108. /// </summary>
  109. IllegalState = 1,
  110. /// <summary>
  111. /// 非法参数
  112. /// </summary>
  113. InvalidParam = 2,
  114. /// <summary>
  115. /// 创建 SOCKET 失败
  116. /// </summary>
  117. SocketCreate = 3,
  118. /// <summary>
  119. /// 绑定 SOCKET 失败
  120. /// </summary>
  121. SocketBind = 4,
  122. /// <summary>
  123. /// 设置 SOCKET 失败
  124. /// </summary>
  125. SocketPrepare = 5,
  126. /// <summary>
  127. /// 监听 SOCKET 失败
  128. /// </summary>
  129. SocketListen = 6,
  130. /// <summary>
  131. /// 创建完成端口失败
  132. /// </summary>
  133. CPCreate = 7,
  134. /// <summary>
  135. /// 创建工作线程失败
  136. /// </summary>
  137. WorkerThreadCreate = 8,
  138. /// <summary>
  139. /// 创建监测线程失败
  140. /// </summary>
  141. DetectThreadCreate = 9,
  142. /// <summary>
  143. /// 绑定完成端口失败
  144. /// </summary>
  145. SocketAttachToCP = 10,
  146. /// <summary>
  147. /// 连接服务器失败
  148. /// </summary>
  149. ConnectServer = 11,
  150. /// <summary>
  151. /// 网络错误
  152. /// </summary>
  153. Network = 12,
  154. /// <summary>
  155. /// 数据处理错误
  156. /// </summary>
  157. DataProc = 13,
  158. /// <summary>
  159. /// 数据发送失败
  160. /// </summary>
  161. DataSend = 14,
  162. /***** SSL Socket 扩展操作结果代码 *****/
  163. /// <summary>
  164. /// SSL 环境未就绪
  165. /// </summary>
  166. SSLEnvNotReady = 101,
  167. };
  168. /// <summary>
  169. /// 数据抓取结果,数据抓取操作的返回值
  170. /// </summary>
  171. public enum FetchResult
  172. {
  173. /// <summary>
  174. /// 成功
  175. /// </summary>
  176. Ok = 0,
  177. /// <summary>
  178. /// 抓取长度过大
  179. /// </summary>
  180. LengthTooLong = 1,
  181. /// <summary>
  182. /// 找不到 ConnID 对应的数据
  183. /// </summary>
  184. DataNotFound = 2,
  185. };
  186. /// <summary>
  187. /// 发送策略
  188. /// </summary>
  189. public enum SendPolicy
  190. {
  191. /// <summary>
  192. /// 打包模式(默认)
  193. /// </summary>
  194. Pack = 0,
  195. /// <summary>
  196. /// 安全模式
  197. /// </summary>
  198. Safe = 1,
  199. /// <summary>
  200. /// 直接模式
  201. /// </summary>
  202. Direct = 2,
  203. };
  204. /// <summary>
  205. /// OnSend 事件同步策略
  206. /// Server 组件和 Agent 组件的 OnSend 事件同步策略
  207. /// </summary>
  208. public enum OnSendSyncPolicy
  209. {
  210. /// <summary>
  211. /// 不同步(默认) :不同步 OnSend 事件,此时可能同时触发 OnReceive 和 OnClose 事件
  212. /// </summary>
  213. OSSP_NONE = 0,
  214. /// <summary>
  215. /// 同步 OnClose :只同步 OnClose 事件,此时可能同时触发 OnReceive 事件
  216. /// </summary>
  217. OSSP_CLOSE = 1,
  218. /// <summary>
  219. /// 同步 OnReceive :(只用于 TCP 组件)同步 OnReceive 和 OnClose 事件,此处不可能同时触发 OnReceive 或 OnClose 事件
  220. /// </summary>
  221. OSSP_RECEIVE = 2,
  222. }
  223. /// <summary>
  224. /// 播送模式 UDP 组件的播送模式(组播或广播)
  225. /// </summary>
  226. public enum CastMode
  227. {
  228. /// <summary>
  229. /// 组播
  230. /// </summary>
  231. Multicast = 0,
  232. /// <summary>
  233. /// 广播
  234. /// </summary>
  235. Broadcast = 1,
  236. }
  237. /// <summary>
  238. /// 名称:IP 地址类型
  239. /// 描述:IP 地址类型枚举值
  240. /// </summary>
  241. public enum IPAddrType
  242. {
  243. /// <summary>
  244. /// 所有
  245. /// </summary>
  246. All = 0,
  247. /// <summary>
  248. /// IPv4
  249. /// </summary>
  250. IPV4 = 1,
  251. /// <summary>
  252. /// IPv6
  253. /// </summary>
  254. IPV6 = 2,
  255. /// <summary>
  256. /// 其他
  257. /// </summary>
  258. Other = 100,
  259. }
  260. /// <summary>
  261. /// 接收状态
  262. /// </summary>
  263. public enum ReceiveState : int
  264. {
  265. /// <summary>
  266. /// 未知
  267. /// </summary>
  268. Unknown = -1,
  269. /// <summary>
  270. /// 唤醒状态
  271. /// </summary>
  272. Resume = 0,
  273. /// <summary>
  274. /// 暂停状态
  275. /// </summary>
  276. Pause = 1,
  277. }
  278. /****************************************************/
  279. /************** sockaddr结构体,udp服务器时OnAccept最后个参数可转化 **************/
  280. [StructLayout(LayoutKind.Sequential)]
  281. public struct in_addr
  282. {
  283. public ulong S_addr;
  284. }
  285. //[StructLayout(LayoutKind.Sequential)]
  286. //public struct in_addr
  287. //{
  288. // public byte s_b1, s_b2, s_b3, s_b4;
  289. //}
  290. [StructLayout(LayoutKind.Sequential)]
  291. public struct sockaddr_in
  292. {
  293. public short sin_family;
  294. public ushort sin_port;
  295. public in_addr sin_addr;
  296. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
  297. public byte[] sLibNamesin_zero;
  298. }
  299. /****************************************************/
  300. [StructLayout(LayoutKind.Sequential)]
  301. public struct WSABUF
  302. {
  303. public int Length;
  304. public IntPtr Buffer;
  305. }
  306. /// <summary>
  307. /// 名称:IP 地址条目结构体
  308. /// 描述:IP 地址的地址簇/地址值结构体
  309. /// </summary>
  310. public struct IPAddr
  311. {
  312. public IPAddrType Type;
  313. public string Address;
  314. public string TypeString;
  315. }
  316. /// <summary>
  317. /// DnsHelper
  318. /// </summary>
  319. public class DnsHelper
  320. {
  321. /// <summary>
  322. /// 获取本机ipv4+ipv6地址
  323. /// hp-socket可用的ip地址结构
  324. /// </summary>
  325. /// <returns></returns>
  326. public static List<IPAddr> GetLocalHostAddressesToIPAddrList()
  327. {
  328. return Dns.GetHostAddresses(Dns.GetHostName()).Where(p => p.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork ||
  329. p.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6).
  330. Select(p => new IPAddr
  331. {
  332. Type = p.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork ? IPAddrType.IPV4 : IPAddrType.IPV6,
  333. Address = p.ToString(),
  334. }).ToList();
  335. }
  336. /// <summary>
  337. /// 获取本机ipv4+ipv6地址
  338. /// .net自带的ip地址结构
  339. /// </summary>
  340. /// <returns></returns>
  341. public static IPAddress[] GetLocalHostAddresses()
  342. {
  343. return Dns.GetHostAddresses(Dns.GetHostName());
  344. }
  345. }
  346. }
  347. /// <summary>
  348. /// ANSI版本
  349. /// </summary>
  350. public class Sdk
  351. {
  352. /// <summary>
  353. /// HPSocket的文件路径
  354. /// </summary>
  355. public const string HPSOCKET_DLL_PATH = "hpsocket4c";
  356. /*****************************************************************************************************/
  357. /******************************************** 公共类、接口 ********************************************/
  358. /*****************************************************************************************************/
  359. /****************************************************/
  360. /************** HPSocket4C.dll 回调函数 **************/
  361. /* Agent & Server & Client */
  362. public delegate HandleResult OnSend(IntPtr pSender, IntPtr connId, IntPtr pData, int length);
  363. public delegate HandleResult OnReceive(IntPtr pSender, IntPtr connId, IntPtr pData, int length);
  364. public delegate HandleResult OnPullReceive(IntPtr pSender, IntPtr connId, int length);
  365. public delegate HandleResult OnClose(IntPtr pSender, IntPtr connId, SocketOperation enOperation, int errorCode);
  366. public delegate HandleResult OnHandShake(IntPtr pSender, IntPtr connId);
  367. /* Agent & Server */
  368. public delegate HandleResult OnShutdown(IntPtr pSender);
  369. /* Agent & Client */
  370. public delegate HandleResult OnPrepareConnect(IntPtr pSender, IntPtr connId /* IntPtr pClient */, IntPtr socket);
  371. public delegate HandleResult OnConnect(IntPtr pSender, IntPtr connId /* IntPtr pClient */);
  372. /* Server */
  373. public delegate HandleResult OnPrepareListen(IntPtr pSender, IntPtr soListen);
  374. public delegate HandleResult OnAccept(IntPtr pSender, IntPtr connId, IntPtr pClient);
  375. /****************************************************/
  376. /************** HPSocket4C.dll 导出函数 **************/
  377. /// <summary>
  378. /// 创建 TcpServer 对象
  379. /// </summary>
  380. /// <param name="pListener"></param>
  381. /// <returns></returns>
  382. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  383. public static extern IntPtr Create_HP_TcpServer(IntPtr pListener);
  384. /// <summary>
  385. /// 创建 TcpClient 对象
  386. /// </summary>
  387. /// <param name="pListener"></param>
  388. /// <returns></returns>
  389. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  390. public static extern IntPtr Create_HP_TcpClient(IntPtr pListener);
  391. /// <summary>
  392. /// 创建 TcpAgent 对象
  393. /// </summary>
  394. /// <param name="pListener"></param>
  395. /// <returns></returns>
  396. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  397. public static extern IntPtr Create_HP_TcpAgent(IntPtr pListener);
  398. /// <summary>
  399. /// 创建 TcpPullServer 对象
  400. /// </summary>
  401. /// <param name="pListener"></param>
  402. /// <returns></returns>
  403. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  404. public static extern IntPtr Create_HP_TcpPullServer(IntPtr pListener);
  405. /// <summary>
  406. /// 创建 TcpPullClient 对象
  407. /// </summary>
  408. /// <param name="pListener"></param>
  409. /// <returns></returns>
  410. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  411. public static extern IntPtr Create_HP_TcpPullClient(IntPtr pListener);
  412. /// <summary>
  413. /// 创建 TcpPullAgent 对象
  414. /// </summary>
  415. /// <param name="pListener"></param>
  416. /// <returns></returns>
  417. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  418. public static extern IntPtr Create_HP_TcpPullAgent(IntPtr pListener);
  419. /// <summary>
  420. /// 创建 HP_TcpPackServer 对象
  421. /// </summary>
  422. /// <param name="pListener"></param>
  423. /// <returns></returns>
  424. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  425. public static extern IntPtr Create_HP_TcpPackServer(IntPtr pListener);
  426. /// <summary>
  427. /// 创建 HP_TcpPackAgent 对象
  428. /// </summary>
  429. /// <param name="pListener"></param>
  430. /// <returns></returns>
  431. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  432. public static extern IntPtr Create_HP_TcpPackAgent(IntPtr pListener);
  433. /// <summary>
  434. /// 创建 HP_TcpPackAgent 对象
  435. /// </summary>
  436. /// <param name="pListener"></param>
  437. /// <returns></returns>
  438. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  439. public static extern IntPtr Create_HP_TcpPackClient(IntPtr pListener);
  440. /// <summary>
  441. /// 创建 UdpServer 对象
  442. /// </summary>
  443. /// <param name="pListener"></param>
  444. /// <returns></returns>
  445. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  446. public static extern IntPtr Create_HP_UdpServer(IntPtr pListener);
  447. /// <summary>
  448. /// 创建 UdpClient 对象
  449. /// </summary>
  450. /// <param name="pListener"></param>
  451. /// <returns></returns>
  452. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  453. public static extern IntPtr Create_HP_UdpClient(IntPtr pListener);
  454. /// <summary>
  455. /// 创建 HP_UdpCast 对象
  456. /// </summary>
  457. /// <param name="pListener"></param>
  458. /// <returns></returns>
  459. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  460. public static extern IntPtr Create_HP_UdpCast(IntPtr pListener);
  461. /// <summary>
  462. /// 销毁 TcpServer 对象
  463. /// </summary>
  464. /// <param name="pServer"></param>
  465. /// <returns></returns>
  466. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  467. public static extern void Destroy_HP_TcpServer(IntPtr pServer);
  468. /// <summary>
  469. /// 销毁 TcpClient 对象
  470. /// </summary>
  471. /// <param name="pClient"></param>
  472. /// <returns></returns>
  473. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  474. public static extern void Destroy_HP_TcpClient(IntPtr pClient);
  475. /// <summary>
  476. /// 销毁 TcpAgent 对象
  477. /// </summary>
  478. /// <param name="pAgent"></param>
  479. /// <returns></returns>
  480. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  481. public static extern void Destroy_HP_TcpAgent(IntPtr pAgent);
  482. /// <summary>
  483. /// 销毁 TcpPullServer 对象
  484. /// </summary>
  485. /// <param name="pClient"></param>
  486. /// <returns></returns>
  487. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  488. public static extern void Destroy_HP_TcpPullServer(IntPtr pServer);
  489. /// <summary>
  490. /// 销毁 TcpPullClient 对象
  491. /// </summary>
  492. /// <param name="pClient"></param>
  493. /// <returns></returns>
  494. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  495. public static extern void Destroy_HP_TcpPullClient(IntPtr pClient);
  496. /// <summary>
  497. /// 销毁 TcpPullAgent 对象
  498. /// </summary>
  499. /// <param name="pAgent"></param>
  500. /// <returns></returns>
  501. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  502. public static extern void Destroy_HP_TcpPullAgent(IntPtr pAgent);
  503. /// <summary>
  504. /// 销毁 HP_TcpPackServer 对象
  505. /// </summary>
  506. /// <param name="pServer"></param>
  507. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  508. public static extern void Destroy_HP_TcpPackServer(IntPtr pServer);
  509. /// <summary>
  510. /// 销毁 HP_TcpPackAgent 对象
  511. /// </summary>
  512. /// <param name="pAgent"></param>
  513. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  514. public static extern void Destroy_HP_TcpPackAgent(IntPtr pAgent);
  515. /// <summary>
  516. /// 销毁 HP_TcpPackClient 对象
  517. /// </summary>
  518. /// <param name="pClient"></param>
  519. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  520. public static extern void Destroy_HP_TcpPackClient(IntPtr pClient);
  521. /// <summary>
  522. /// 销毁 UdpServer 对象
  523. /// </summary>
  524. /// <param name="pServer"></param>
  525. /// <returns></returns>
  526. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  527. public static extern void Destroy_HP_UdpServer(IntPtr pServer);
  528. /// <summary>
  529. /// 销毁 UdpClient 对象
  530. /// </summary>
  531. /// <param name="pClient"></param>
  532. /// <returns></returns>
  533. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  534. public static extern void Destroy_HP_UdpClient(IntPtr pClient);
  535. /// <summary>
  536. /// 销毁 HP_UdpCast 对象
  537. /// </summary>
  538. /// <param name="pCast"></param>
  539. /// <returns></returns>
  540. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  541. public static extern void Destroy_HP_UdpCast(IntPtr pCast);
  542. /// <summary>
  543. /// 创建 TcpServerListener 对象
  544. /// </summary>
  545. /// <returns></returns>
  546. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  547. public static extern IntPtr Create_HP_TcpServerListener();
  548. /// <summary>
  549. /// 创建 TcpClientListener 对象
  550. /// </summary>
  551. /// <returns></returns>
  552. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  553. public static extern IntPtr Create_HP_TcpClientListener();
  554. /// <summary>
  555. /// 创建 TcpAgentListener 对象
  556. /// </summary>
  557. /// <returns></returns>
  558. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  559. public static extern IntPtr Create_HP_TcpAgentListener();
  560. /// <summary>
  561. /// 创建 TcpPullServerListener 对象
  562. /// </summary>
  563. /// <returns></returns>
  564. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  565. public static extern IntPtr Create_HP_TcpPullServerListener();
  566. /// <summary>
  567. /// 创建 TcpPullClientListener 对象
  568. /// </summary>
  569. /// <returns></returns>
  570. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  571. public static extern IntPtr Create_HP_TcpPullClientListener();
  572. /// <summary>
  573. /// 创建 TcpPullAgentListener 对象
  574. /// </summary>
  575. /// <returns></returns>
  576. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  577. public static extern IntPtr Create_HP_TcpPullAgentListener();
  578. /// <summary>
  579. /// 创建 TcpPackServerListener 对象
  580. /// </summary>
  581. /// <returns></returns>
  582. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  583. public static extern IntPtr Create_HP_TcpPackServerListener();
  584. /// <summary>
  585. /// 创建 TcpPackClientListener 对象
  586. /// </summary>
  587. /// <returns></returns>
  588. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  589. public static extern IntPtr Create_HP_TcpPackClientListener();
  590. /// <summary>
  591. /// 创建 TcpPackAgentListener 对象
  592. /// </summary>
  593. /// <returns></returns>
  594. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  595. public static extern IntPtr Create_HP_TcpPackAgentListener();
  596. /// <summary>
  597. /// 创建 UdpServerListener 对象
  598. /// </summary>
  599. /// <returns></returns>
  600. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  601. public static extern IntPtr Create_HP_UdpServerListener();
  602. /// <summary>
  603. /// 创建 UdpClientListener 对象
  604. /// </summary>
  605. /// <returns></returns>
  606. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  607. public static extern IntPtr Create_HP_UdpClientListener();
  608. /// <summary>
  609. /// 创建 HP_UdpCastListener 对象
  610. /// </summary>
  611. /// <returns></returns>
  612. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  613. public static extern IntPtr Create_HP_UdpCastListener();
  614. /// <summary>
  615. /// 销毁 TcpServerListener 对象
  616. /// </summary>
  617. /// <param name="pListener"></param>
  618. /// <returns></returns>
  619. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  620. public static extern void Destroy_HP_TcpServerListener(IntPtr pListener);
  621. /// <summary>
  622. /// 销毁 TcpClientListener 对象
  623. /// </summary>
  624. /// <param name="pListener"></param>
  625. /// <returns></returns>
  626. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  627. public static extern void Destroy_HP_TcpClientListener(IntPtr pListener);
  628. /// <summary>
  629. /// 销毁 TcpAgentListener 对象
  630. /// </summary>
  631. /// <param name="pListener"></param>
  632. /// <returns></returns>
  633. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  634. public static extern void Destroy_HP_TcpAgentListener(IntPtr pListener);
  635. /// <summary>
  636. /// 销毁 TcpPullServerListener 对象
  637. /// </summary>
  638. /// <param name="pListener"></param>
  639. /// <returns></returns>
  640. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  641. public static extern void Destroy_HP_TcpPullServerListener(IntPtr pListener);
  642. /// <summary>
  643. /// 销毁 TcpPullClientListener 对象
  644. /// </summary>
  645. /// <param name="pListener"></param>
  646. /// <returns></returns>
  647. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  648. public static extern void Destroy_HP_TcpPullClientListener(IntPtr pListener);
  649. /// <summary>
  650. /// 销毁 TcpPullAgentListener 对象
  651. /// </summary>
  652. /// <param name="pListener"></param>
  653. /// <returns></returns>
  654. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  655. public static extern void Destroy_HP_TcpPullAgentListener(IntPtr pListener);
  656. /// <summary>
  657. /// 销毁 TcpPackServerListener 对象
  658. /// </summary>
  659. /// <param name="pListener"></param>
  660. /// <returns></returns>
  661. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  662. public static extern void Destroy_HP_TcpPackServerListener(IntPtr pListener);
  663. /// <summary>
  664. /// 销毁 TcpPackClientListener 对象
  665. /// </summary>
  666. /// <param name="pListener"></param>
  667. /// <returns></returns>
  668. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  669. public static extern void Destroy_HP_TcpPackClientListener(IntPtr pListener);
  670. /// <summary>
  671. /// 销毁 TcpPackAgentListener 对象
  672. /// </summary>
  673. /// <param name="pListener"></param>
  674. /// <returns></returns>
  675. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  676. public static extern void Destroy_HP_TcpPackAgentListener(IntPtr pListener);
  677. /// <summary>
  678. /// 销毁 UdpServerListener 对象
  679. /// </summary>
  680. /// <param name="pListener"></param>
  681. /// <returns></returns>
  682. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  683. public static extern void Destroy_HP_UdpServerListener(IntPtr pListener);
  684. /// <summary>
  685. /// 销毁 UdpClientListener 对象
  686. /// </summary>
  687. /// <param name="pListener"></param>
  688. /// <returns></returns>
  689. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  690. public static extern void Destroy_HP_UdpClientListener(IntPtr pListener);
  691. /// <summary>
  692. /// 销毁 HP_UdpCastListener 对象
  693. /// </summary>
  694. /// <param name="pListener"></param>
  695. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  696. public static extern void Destroy_HP_UdpCastListener(IntPtr pListener);
  697. /**********************************************************************************/
  698. /***************************** Server 回调函数设置方法 *****************************/
  699. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  700. public static extern void HP_Set_FN_Server_OnPrepareListen(IntPtr pListener, OnPrepareListen fn);
  701. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  702. public static extern void HP_Set_FN_Server_OnAccept(IntPtr pListener, OnAccept fn);
  703. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  704. public static extern void HP_Set_FN_Server_OnHandShake(IntPtr pListener, OnHandShake fn);
  705. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  706. public static extern void HP_Set_FN_Server_OnSend(IntPtr pListener, OnSend fn);
  707. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  708. public static extern void HP_Set_FN_Server_OnReceive(IntPtr pListener, OnReceive fn);
  709. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  710. public static extern void HP_Set_FN_Server_OnPullReceive(IntPtr pListener, OnPullReceive fn);
  711. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  712. public static extern void HP_Set_FN_Server_OnClose(IntPtr pListener, OnClose fn);
  713. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  714. public static extern void HP_Set_FN_Server_OnShutdown(IntPtr pListener, OnShutdown fn);
  715. /**********************************************************************************/
  716. /***************************** Client 回调函数设置方法 *****************************/
  717. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  718. public static extern void HP_Set_FN_Client_OnPrepareConnect(IntPtr pListener, OnPrepareConnect fn);
  719. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  720. public static extern void HP_Set_FN_Client_OnConnect(IntPtr pListener, OnConnect fn);
  721. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  722. public static extern void HP_Set_FN_Client_OnHandShake(IntPtr pListener, OnHandShake fn);
  723. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  724. public static extern void HP_Set_FN_Client_OnSend(IntPtr pListener, OnSend fn);
  725. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  726. public static extern void HP_Set_FN_Client_OnReceive(IntPtr pListener, OnReceive fn);
  727. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  728. public static extern void HP_Set_FN_Client_OnPullReceive(IntPtr pListener, OnPullReceive fn);
  729. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  730. public static extern void HP_Set_FN_Client_OnClose(IntPtr pListener, OnClose fn);
  731. /**********************************************************************************/
  732. /****************************** Agent 回调函数设置方法 *****************************/
  733. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  734. public static extern void HP_Set_FN_Agent_OnPrepareConnect(IntPtr pListener, OnPrepareConnect fn);
  735. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  736. public static extern void HP_Set_FN_Agent_OnConnect(IntPtr pListener, OnConnect fn);
  737. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  738. public static extern void HP_Set_FN_Agent_OnHandShake(IntPtr pListener, OnHandShake fn);
  739. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  740. public static extern void HP_Set_FN_Agent_OnSend(IntPtr pListener, OnSend fn);
  741. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  742. public static extern void HP_Set_FN_Agent_OnReceive(IntPtr pListener, OnReceive fn);
  743. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  744. public static extern void HP_Set_FN_Agent_OnPullReceive(IntPtr pListener, OnPullReceive fn);
  745. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  746. public static extern void HP_Set_FN_Agent_OnClose(IntPtr pListener, OnClose fn);
  747. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  748. public static extern void HP_Set_FN_Agent_OnShutdown(IntPtr pListener, OnShutdown fn);
  749. /**************************************************************************/
  750. /***************************** Server 操作方法 *****************************/
  751. /// <summary>
  752. /// 名称:启动通信组件
  753. /// 描述:启动服务端通信组件,启动完成后可开始接收客户端连接并收发数据
  754. /// </summary>
  755. /// <param name="pServer"></param>
  756. /// <param name="pszBindAddress">监听地址</param>
  757. /// <param name="usPort">监听端口</param>
  758. /// <returns>失败,可通过 GetLastError() 获取错误代码</returns>
  759. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  760. public static extern bool HP_Server_Start(IntPtr pServer, string pszBindAddress, ushort usPort);
  761. /// <summary>
  762. /// 关闭服务端通信组件,关闭完成后断开所有客户端连接并释放所有资源
  763. /// </summary>
  764. /// <param name="pServer"></param>
  765. /// <returns>失败,可通过 GetLastError() 获取错误代码</returns>
  766. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  767. public static extern bool HP_Server_Stop(IntPtr pServer);
  768. /// <summary>
  769. /// 用户通过该方法向指定客户端发送数据
  770. /// </summary>
  771. /// <param name="pServer"></param>
  772. /// <param name="connId">连接 ID</param>
  773. /// <param name="pBuffer">发送数据长度</param>
  774. /// <param name="length">发送数据长度</param>
  775. /// <returns></returns>
  776. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  777. public static extern bool HP_Server_Send(IntPtr pServer, IntPtr connId, byte[] pBuffer, int length);
  778. /// <summary>
  779. /// 用户通过该方法向指定客户端发送数据
  780. /// </summary>
  781. /// <param name="pServer"></param>
  782. /// <param name="connId">连接 ID</param>
  783. /// <param name="pBuffer">发送数据长度</param>
  784. /// <param name="length">发送数据长度</param>
  785. /// <returns></returns>
  786. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  787. public static extern bool HP_Server_Send(IntPtr pServer, IntPtr connId, IntPtr pBuffer, int length);
  788. /// <summary>
  789. /// 用户通过该方法向指定客户端发送数据
  790. /// </summary>
  791. /// <param name="pServer"></param>
  792. /// <param name="connId"></param>
  793. /// <param name="pBuffer"></param>
  794. /// <param name="length"></param>
  795. /// <param name="iOffset">针对pBuffer的偏移</param>
  796. /// <returns></returns>
  797. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  798. public static extern bool HP_Server_SendPart(IntPtr pServer, IntPtr connId, byte[] pBuffer, int length, int iOffset);
  799. /// <summary>
  800. /// 用户通过该方法向指定客户端发送数据
  801. /// </summary>
  802. /// <param name="pServer"></param>
  803. /// <param name="connId"></param>
  804. /// <param name="pBuffer"></param>
  805. /// <param name="length"></param>
  806. /// <param name="iOffset">针对pBuffer的偏移</param>
  807. /// <returns></returns>
  808. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  809. public static extern bool HP_Server_SendPart(IntPtr pServer, IntPtr connId, IntPtr pBuffer, int length, int iOffset);
  810. /// <summary>
  811. /// 发送多组数据
  812. /// 向指定连接发送多组数据
  813. /// TCP - 顺序发送所有数据包
  814. /// UDP - 把所有数据包组合成一个数据包发送(数据包的总长度不能大于设置的 UDP 包最大长度)
  815. /// </summary>
  816. /// <param name="pServer"></param>
  817. /// <param name="connId">连接 ID</param>
  818. /// <param name="pBuffers">发送缓冲区数组</param>
  819. /// <param name="iCount">发送缓冲区数目</param>
  820. /// <returns>TRUE.成功,FALSE.失败,可通过 Windows API 函数 ::GetLastError() 获取 Windows 错误代码</returns>
  821. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  822. public static extern bool HP_Server_SendPackets(IntPtr pServer, IntPtr connId, WSABUF[] pBuffers, int iCount);
  823. /// <summary>
  824. /// 名称:暂停/恢复接收
  825. /// 描述:暂停/恢复某个连接的数据接收工作
  826. /// </summary>
  827. /// <param name="pServer"></param>
  828. /// <param name="dwConnID">连接 ID</param>
  829. /// <param name="bPause">TRUE - 暂停, FALSE - 恢复</param>
  830. /// <returns></returns>
  831. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  832. public static extern bool HP_Server_PauseReceive(IntPtr pServer, IntPtr dwConnID, bool bPause);
  833. /// <summary>
  834. /// 断开与某个客户端的连接
  835. /// </summary>
  836. /// <param name="pServer"></param>
  837. /// <param name="connId">连接 ID</param>
  838. /// <param name="bForce">是否强制断开连接</param>
  839. /// <returns></returns>
  840. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  841. public static extern bool HP_Server_Disconnect(IntPtr pServer, IntPtr connId, bool bForce);
  842. /// <summary>
  843. /// 断开超过指定时长的连接
  844. /// </summary>
  845. /// <param name="pServer"></param>
  846. /// <param name="dwPeriod">时长(毫秒)</param>
  847. /// <param name="bForce">是否强制断开连接</param>
  848. /// <returns></returns>
  849. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  850. public static extern bool HP_Server_DisconnectLongConnections(IntPtr pServer, uint dwPeriod, bool bForce);
  851. /// <summary>
  852. /// 断开超过指定时长的静默连接
  853. /// </summary>
  854. /// <param name="pServer"></param>
  855. /// <param name="dwPeriod">时长(毫秒)</param>
  856. /// <param name="bForce">是否强制断开连接</param>
  857. /// <returns></returns>
  858. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  859. public static extern bool HP_Server_DisconnectSilenceConnections(IntPtr pServer, uint dwPeriod, bool bForce);
  860. /******************************************************************************/
  861. /***************************** Server 属性访问方法 *****************************/
  862. /// <summary>
  863. /// 设置数据发送策略
  864. /// </summary>
  865. /// <param name="pServer"></param>
  866. /// <param name="enSendPolicy"></param>
  867. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  868. public static extern void HP_Server_SetSendPolicy(IntPtr pServer, SendPolicy enSendPolicy);
  869. /// <summary>
  870. /// 获取数据发送策略
  871. /// </summary>
  872. /// <param name="pServer"></param>
  873. /// <returns></returns>
  874. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  875. public static extern SendPolicy HP_Server_GetSendPolicy(IntPtr pServer);
  876. /// <summary>
  877. /// 设置连接的附加数据
  878. /// 是否为连接绑定附加数据或者绑定什么样的数据,均由应用程序只身决定
  879. /// </summary>
  880. /// <param name="pServer"></param>
  881. /// <param name="connId">连接 ID</param>
  882. /// <param name="pExtra"></param>
  883. /// <returns>若返回 false 失败则为(无效的连接 ID)</returns>
  884. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  885. public static extern bool HP_Server_SetConnectionExtra(IntPtr pServer, IntPtr connId, IntPtr pExtra);
  886. /// <summary>
  887. /// 获取连接的附加数据
  888. /// 是否为连接绑定附加数据或者绑定什么样的数据,均由应用程序只身决定
  889. /// </summary>
  890. /// <param name="pServer"></param>
  891. /// <param name="connId">连接 ID</param>
  892. /// <param name="pExtra">数据指针</param>
  893. /// <returns>若返回 false 失败则为(无效的连接 ID)</returns>
  894. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  895. public static extern bool HP_Server_GetConnectionExtra(IntPtr pServer, IntPtr connId, ref IntPtr pExtra);
  896. /// <summary>
  897. /// 检测是否为安全连接(SSL/HTTPS)
  898. /// </summary>
  899. /// <param name="pServer"></param>
  900. /// <returns></returns>
  901. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  902. public static extern bool HP_Server_IsSecure(IntPtr pServer);
  903. /// <summary>
  904. /// 检查通信组件是否已启动
  905. /// </summary>
  906. /// <param name="pServer"></param>
  907. /// <returns></returns>
  908. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  909. public static extern bool HP_Server_HasStarted(IntPtr pServer);
  910. /// <summary>
  911. /// 查看通信组件当前状态
  912. /// </summary>
  913. /// <param name="pServer"></param>
  914. /// <returns></returns>
  915. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  916. public static extern ServiceState HP_Server_GetState(IntPtr pServer);
  917. /// <summary>
  918. /// 获取最近一次失败操作的错误代码
  919. /// </summary>
  920. /// <param name="pServer"></param>
  921. /// <returns></returns>
  922. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  923. public static extern SocketError HP_Server_GetLastError(IntPtr pServer);
  924. /// <summary>
  925. /// 获取最近一次失败操作的错误描述
  926. /// </summary>
  927. /// <param name="pServer"></param>
  928. /// <returns></returns>
  929. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  930. public static extern IntPtr HP_Server_GetLastErrorDesc(IntPtr pServer);
  931. /// <summary>
  932. /// 获取连接中未发出数据的长度
  933. /// </summary>
  934. /// <param name="pServer"></param>
  935. /// <param name="connId"></param>
  936. /// <param name="piPending"></param>
  937. /// <returns></returns>
  938. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  939. public static extern bool HP_Server_GetPendingDataLength(IntPtr pServer, IntPtr connId, ref int piPending);
  940. /// <summary>
  941. /// 获取连接的数据接收状态
  942. /// </summary>
  943. /// <param name="pServer"></param>
  944. /// <param name="dwConnID"></param>
  945. /// <param name="pbPaused"></param>
  946. /// <returns></returns>
  947. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  948. public static extern bool HP_Server_IsPauseReceive(IntPtr pServer, IntPtr dwConnID, ref int pbPaused);
  949. /// <summary>
  950. /// 检测是否有效连接
  951. /// </summary>
  952. /// <param name="pServer"></param>
  953. /// <param name="dwConnID"></param>
  954. /// <returns></returns>
  955. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  956. public static extern bool HP_Server_IsConnected(IntPtr pServer, IntPtr dwConnID);
  957. /// <summary>
  958. /// 获取客户端连接数
  959. /// </summary>
  960. /// <param name="pServer"></param>
  961. /// <returns></returns>
  962. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  963. public static extern uint HP_Server_GetConnectionCount(IntPtr pServer);
  964. /// <summary>
  965. /// 获取所有连接的 CONNID
  966. /// </summary>
  967. /// <param name="pServer"></param>
  968. /// <param name="pIDs"></param>
  969. /// <param name="pdwCount"></param>
  970. /// <returns></returns>
  971. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  972. public static extern bool HP_Server_GetAllConnectionIDs(IntPtr pServer, IntPtr[] pIDs, ref uint pdwCount);
  973. /// <summary>
  974. /// 获取某个客户端连接时长(毫秒)
  975. /// </summary>
  976. /// <param name="pServer"></param>
  977. /// <param name="connId"></param>
  978. /// <param name="pdwPeriod"></param>
  979. /// <returns></returns>
  980. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  981. public static extern bool HP_Server_GetConnectPeriod(IntPtr pServer, IntPtr connId, ref uint pdwPeriod);
  982. /// <summary>
  983. /// 获取某个连接静默时间(毫秒)
  984. /// </summary>
  985. /// <param name="pServer"></param>
  986. /// <param name="connId"></param>
  987. /// <param name="pdwPeriod"></param>
  988. /// <returns></returns>
  989. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  990. public static extern bool HP_Server_GetSilencePeriod(IntPtr pServer, IntPtr connId, ref uint pdwPeriod);
  991. /// <summary>
  992. /// 获取监听 Socket 的地址信息
  993. /// </summary>
  994. /// <param name="pServer"></param>
  995. /// <param name="lpszAddress"></param>
  996. /// <param name="piAddressLen"></param>
  997. /// <param name="pusPort"></param>
  998. /// <returns></returns>
  999. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1000. public static extern bool HP_Server_GetListenAddress(IntPtr pServer, [MarshalAs(UnmanagedType.LPStr)] StringBuilder lpszAddress, ref int piAddressLen, ref ushort pusPort);
  1001. /// <summary>
  1002. /// 获取某个连接的本地地址信息
  1003. /// </summary>
  1004. /// <param name="pServer"></param>
  1005. /// <param name="connId"></param>
  1006. /// <param name="lpszAddress"></param>
  1007. /// <param name="piAddressLen">传入传出值,大小最好在222.222.222.222的长度以上</param>
  1008. /// <param name="pusPort"></param>
  1009. /// <returns></returns>
  1010. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1011. public static extern bool HP_Server_GetLocalAddress(IntPtr pServer, IntPtr connId, [MarshalAs(UnmanagedType.LPStr)] StringBuilder lpszAddress, ref int piAddressLen, ref ushort pusPort);
  1012. /// <summary>
  1013. /// 获取某个连接的远程地址信息
  1014. /// </summary>
  1015. /// <param name="pServer"></param>
  1016. /// <param name="connId"></param>
  1017. /// <param name="lpszAddress"></param>
  1018. /// <param name="piAddressLen">传入传出值,大小最好在222.222.222.222的长度以上</param>
  1019. /// <param name="pusPort"></param>
  1020. /// <returns></returns>
  1021. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1022. public static extern bool HP_Server_GetRemoteAddress(IntPtr pServer, IntPtr connId, [MarshalAs(UnmanagedType.LPStr)] StringBuilder lpszAddress, ref int piAddressLen, ref ushort pusPort);
  1023. /// <summary>
  1024. /// 设置 OnSend 事件同步策略(默认:OSSP_NONE,不同步)
  1025. /// </summary>
  1026. /// <param name="pServer"></param>
  1027. /// <param name="syncPolicy"></param>
  1028. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1029. public static extern void HP_Server_SetOnSendSyncPolicy(IntPtr pServer, OnSendSyncPolicy syncPolicy);
  1030. /// <summary>
  1031. /// 获取 OnSend 事件同步策略
  1032. /// </summary>
  1033. /// <param name="pServer"></param>
  1034. /// <returns></returns>
  1035. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1036. public static extern OnSendSyncPolicy HP_Server_GetOnSendSyncPolicy(IntPtr pServer);
  1037. /// <summary>
  1038. /// 设置 Socket 缓存对象锁定时间(毫秒,在锁定期间该 Socket 缓存对象不能被获取使用)
  1039. /// </summary>
  1040. /// <param name="pServer"></param>
  1041. /// <param name="dwFreeSocketObjLockTime"></param>
  1042. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1043. public static extern void HP_Server_SetFreeSocketObjLockTime(IntPtr pServer, uint dwFreeSocketObjLockTime);
  1044. /// <summary>
  1045. /// 设置 Socket 缓存池大小(通常设置为平均并发连接数量的 1/3 - 1/2)
  1046. /// </summary>
  1047. /// <param name="pServer"></param>
  1048. /// <param name="dwFreeSocketObjPool"></param>
  1049. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1050. public static extern void HP_Server_SetFreeSocketObjPool(IntPtr pServer, uint dwFreeSocketObjPool);
  1051. /// <summary>
  1052. /// 设置内存块缓存池大小(通常设置为 Socket 缓存池大小的 2 - 3 倍)
  1053. /// </summary>
  1054. /// <param name="pServer"></param>
  1055. /// <param name="dwFreeBufferObjPool"></param>
  1056. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1057. public static extern void HP_Server_SetFreeBufferObjPool(IntPtr pServer, uint dwFreeBufferObjPool);
  1058. /// <summary>
  1059. /// 设置 Socket 缓存池回收阀值(通常设置为 Socket 缓存池大小的 3 倍)
  1060. /// </summary>
  1061. /// <param name="pServer"></param>
  1062. /// <param name="dwFreeSocketObjHold"></param>
  1063. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1064. public static extern void HP_Server_SetFreeSocketObjHold(IntPtr pServer, uint dwFreeSocketObjHold);
  1065. /// <summary>
  1066. /// 设置内存块缓存池回收阀值(通常设置为内存块缓存池大小的 3 倍)
  1067. /// </summary>
  1068. /// <param name="pServer"></param>
  1069. /// <param name="dwFreeBufferObjHold"></param>
  1070. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1071. public static extern void HP_Server_SetFreeBufferObjHold(IntPtr pServer, uint dwFreeBufferObjHold);
  1072. /// <summary>
  1073. /// 设置最大连接数(组件会根据设置值预分配内存,因此需要根据实际情况设置,不宜过大)
  1074. /// </summary>
  1075. /// <param name="pServer"></param>
  1076. /// <param name="dwMaxConnectionCount"></param>
  1077. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1078. public static extern void HP_Server_SetMaxConnectionCount(IntPtr pServer, uint dwWMaxConnectionCount);
  1079. /// <summary>
  1080. /// 设置工作线程数量(通常设置为 2 * CPU + 2)
  1081. /// </summary>
  1082. /// <param name="pServer"></param>
  1083. /// <param name="dwWorkerThreadCount"></param>
  1084. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1085. public static extern void HP_Server_SetWorkerThreadCount(IntPtr pServer, uint dwWorkerThreadCount);
  1086. /// <summary>
  1087. /// 设置是否标记静默时间(设置为 TRUE 时 DisconnectSilenceConnections() 和 GetSilencePeriod() 才有效,默认:FALSE)
  1088. /// </summary>
  1089. /// <param name="pServer"></param>
  1090. /// <param name="bMarkSilence"></param>
  1091. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1092. public static extern void HP_Server_SetMarkSilence(IntPtr pServer, bool bMarkSilence);
  1093. /// <summary>
  1094. /// 获取 Socket 缓存对象锁定时间
  1095. /// </summary>
  1096. /// <param name="pServer"></param>
  1097. /// <returns></returns>
  1098. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1099. public static extern uint HP_Server_GetFreeSocketObjLockTime(IntPtr pServer);
  1100. /// <summary>
  1101. /// 获取 Socket 缓存池大小
  1102. /// </summary>
  1103. /// <param name="pServer"></param>
  1104. /// <returns></returns>
  1105. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1106. public static extern uint HP_Server_GetFreeSocketObjPool(IntPtr pServer);
  1107. /// <summary>
  1108. /// 获取内存块缓存池大小
  1109. /// </summary>
  1110. /// <param name="pServer"></param>
  1111. /// <returns></returns>
  1112. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1113. public static extern uint HP_Server_GetFreeBufferObjPool(IntPtr pServer);
  1114. /// <summary>
  1115. /// 获取 Socket 缓存池回收阀值
  1116. /// </summary>
  1117. /// <param name="pServer"></param>
  1118. /// <returns></returns>
  1119. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1120. public static extern uint HP_Server_GetFreeSocketObjHold(IntPtr pServer);
  1121. /// <summary>
  1122. /// 获取内存块缓存池回收阀值
  1123. /// </summary>
  1124. /// <param name="pServer"></param>
  1125. /// <returns></returns>
  1126. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1127. public static extern uint HP_Server_GetFreeBufferObjHold(IntPtr pServer);
  1128. /// <summary>
  1129. /// 获取最大连接数
  1130. /// </summary>
  1131. /// <param name="pServer"></param>
  1132. /// <returns></returns>
  1133. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1134. public static extern uint HP_Server_GetMaxConnectionCount(IntPtr pServer);
  1135. /// <summary>
  1136. /// 获取工作线程数量
  1137. /// </summary>
  1138. /// <param name="pServer"></param>
  1139. /// <returns></returns>
  1140. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1141. public static extern uint HP_Server_GetWorkerThreadCount(IntPtr pServer);
  1142. /// <summary>
  1143. /// 检测是否标记静默时间
  1144. /// </summary>
  1145. /// <param name="pServer"></param>
  1146. /// <returns></returns>
  1147. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1148. public static extern bool HP_Server_IsMarkSilence(IntPtr pServer);
  1149. /**********************************************************************************/
  1150. /***************************** TCP Server 操作方法 *****************************/
  1151. /// <summary>
  1152. /// 名称:发送小文件
  1153. /// 描述:向指定连接发送 4096 KB 以下的小文件
  1154. /// </summary>
  1155. /// <param name="pServer"></param>
  1156. /// <param name="connId">连接 ID</param>
  1157. /// <param name="lpszFileName">文件路径</param>
  1158. /// <param name="pHead">头部附加数据</param>
  1159. /// <param name="pTail">尾部附加数据</param>
  1160. /// <returns>TRUE.成功 FALSE -- 失败,可通过 Windows API 函数 ::GetLastError() 获取 Windows 错误代码</returns>
  1161. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1162. public static extern bool HP_TcpServer_SendSmallFile(IntPtr pServer, IntPtr connId, string lpszFileName, ref WSABUF pHead, ref WSABUF pTail);
  1163. /**********************************************************************************/
  1164. /***************************** TCP Server 属性访问方法 *****************************/
  1165. /// <summary>
  1166. /// 设置 Accept 预投递数量(根据负载调整设置,Accept 预投递数量越大则支持的并发连接请求越多)
  1167. /// </summary>
  1168. /// <param name="pServer"></param>
  1169. /// <param name="dwAcceptSocketCount"></param>
  1170. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1171. public static extern void HP_TcpServer_SetAcceptSocketCount(IntPtr pServer, uint dwAcceptSocketCount);
  1172. /// <summary>
  1173. /// 设置通信数据缓冲区大小(根据平均通信数据包大小调整设置,通常设置为 1024 的倍数)
  1174. /// </summary>
  1175. /// <param name="pServer"></param>
  1176. /// <param name="dwSocketBufferSize"></param>
  1177. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1178. public static extern void HP_TcpServer_SetSocketBufferSize(IntPtr pServer, uint dwSocketBufferSize);
  1179. /// <summary>
  1180. /// 设置监听 Socket 的等候队列大小(根据并发连接数量调整设置)
  1181. /// </summary>
  1182. /// <param name="pServer"></param>
  1183. /// <param name="dwSocketListenQueue"></param>
  1184. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1185. public static extern void HP_TcpServer_SetSocketListenQueue(IntPtr pServer, uint dwSocketListenQueue);
  1186. /// <summary>
  1187. /// 设置心跳包间隔(毫秒,0 则不发送心跳包)
  1188. /// </summary>
  1189. /// <param name="pServer"></param>
  1190. /// <param name="dwKeepAliveTime"></param>
  1191. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1192. public static extern void HP_TcpServer_SetKeepAliveTime(IntPtr pServer, uint dwKeepAliveTime);
  1193. /// <summary>
  1194. /// 设置心跳确认包检测间隔(毫秒,0 不发送心跳包,如果超过若干次 [默认:WinXP 5 次, Win7 10 次] 检测不到心跳确认包则认为已断线)
  1195. /// </summary>
  1196. /// <param name="pServer"></param>
  1197. /// <param name="dwKeepAliveInterval"></param>
  1198. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1199. public static extern void HP_TcpServer_SetKeepAliveInterval(IntPtr pServer, uint dwKeepAliveInterval);
  1200. /// <summary>
  1201. /// 获取 Accept 预投递数量
  1202. /// </summary>
  1203. /// <param name="pServer"></param>
  1204. /// <returns></returns>
  1205. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1206. public static extern uint HP_TcpServer_GetAcceptSocketCount(IntPtr pServer);
  1207. /// <summary>
  1208. /// 获取通信数据缓冲区大小
  1209. /// </summary>
  1210. /// <param name="pServer"></param>
  1211. /// <returns></returns>
  1212. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1213. public static extern uint HP_TcpServer_GetSocketBufferSize(IntPtr pServer);
  1214. /// <summary>
  1215. /// 获取监听 Socket 的等候队列大小
  1216. /// </summary>
  1217. /// <param name="pServer"></param>
  1218. /// <returns></returns>
  1219. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1220. public static extern uint HP_TcpServer_GetSocketListenQueue(IntPtr pServer);
  1221. /// <summary>
  1222. /// 获取心跳检查次数
  1223. /// </summary>
  1224. /// <param name="pServer"></param>
  1225. /// <returns></returns>
  1226. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1227. public static extern uint HP_TcpServer_GetKeepAliveTime(IntPtr pServer);
  1228. /// <summary>
  1229. /// 获取心跳检查间隔
  1230. /// </summary>
  1231. /// <param name="pServer"></param>
  1232. /// <returns></returns>
  1233. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1234. public static extern uint HP_TcpServer_GetKeepAliveInterval(IntPtr pServer);
  1235. /**********************************************************************************/
  1236. /***************************** UDP Server 属性访问方法 *****************************/
  1237. /// <summary>
  1238. /// 设置数据报文最大长度(建议在局域网环境下不超过 1472 字节,在广域网环境下不超过 548 字节)
  1239. /// </summary>
  1240. /// <param name="pServer"></param>
  1241. /// <param name="dwMaxDatagramSize"></param>
  1242. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1243. public static extern void HP_UdpServer_SetMaxDatagramSize(IntPtr pServer, uint dwMaxDatagramSize);
  1244. /// <summary>
  1245. /// 获取数据报文最大长度
  1246. /// </summary>
  1247. /// <param name="pServer"></param>
  1248. /// <returns></returns>
  1249. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1250. public static extern uint HP_UdpServer_GetMaxDatagramSize(IntPtr pServer);
  1251. /// <summary>
  1252. /// 设置 Receive 预投递数量(根据负载调整设置,Receive 预投递数量越大则丢包概率越小)
  1253. /// </summary>
  1254. /// <param name="pServer"></param>
  1255. /// <param name="dwPostReceiveCount"></param>
  1256. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1257. public static extern void HP_UdpServer_SetPostReceiveCount(IntPtr pServer, uint dwPostReceiveCount);
  1258. /// <summary>
  1259. /// 获取 Receive 预投递数量
  1260. /// </summary>
  1261. /// <param name="pServer"></param>
  1262. /// <returns></returns>
  1263. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1264. public static extern uint HP_UdpServer_GetPostReceiveCount(IntPtr pServer);
  1265. /// <summary>
  1266. /// 设置监测包尝试次数(0 则不发送监测跳包,如果超过最大尝试次数则认为已断线)
  1267. /// </summary>
  1268. /// <param name="pServer"></param>
  1269. /// <param name="dwMaxDatagramSize"></param>
  1270. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1271. public static extern void HP_UdpServer_SetDetectAttempts(IntPtr pServer, uint dwMaxDatagramSize);
  1272. /// <summary>
  1273. /// 设置监测包发送间隔(秒,0 不发送监测包)
  1274. /// </summary>
  1275. /// <param name="pServer"></param>
  1276. /// <param name="dwMaxDatagramSize"></param>
  1277. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1278. public static extern void HP_UdpServer_SetDetectInterval(IntPtr pServer, uint dwMaxDatagramSize);
  1279. /// <summary>
  1280. /// 获取心跳检查次数
  1281. /// </summary>
  1282. /// <param name="pServer"></param>
  1283. /// <returns></returns>
  1284. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1285. public static extern uint HP_UdpServer_GetDetectAttempts(IntPtr pServer);
  1286. /// <summary>
  1287. /// 获取心跳检查间隔
  1288. /// </summary>
  1289. /// <param name="pServer"></param>
  1290. /// <returns></returns>
  1291. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1292. public static extern uint HP_UdpServer_GetDetectInterval(IntPtr pServer);
  1293. /******************************************************************************/
  1294. /***************************** Client 组件操作方法 *****************************/
  1295. /// <summary>
  1296. /// 启动客户端通信组件并连接服务端,启动完成后可开始收发数据
  1297. /// </summary>
  1298. /// <param name="pClient"></param>
  1299. /// <param name="pszRemoteAddress">服务端地址</param>
  1300. /// <param name="usPort">服务端端口</param>
  1301. /// <param name="bAsyncConnect">是否采用异步 Connect</param>
  1302. /// <returns>失败,可通过 HP_Client_GetLastError() 获取错误代码</returns>
  1303. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1304. public static extern bool HP_Client_Start(IntPtr pClient, string pszRemoteAddress, ushort usPort, bool bAsyncConnect);
  1305. /// <summary>
  1306. /// 启动通信组件(并指定绑定地址), 启动客户端通信组件并连接服务端,启动完成后可开始收发数据
  1307. /// </summary>
  1308. /// <param name="pClient"></param>
  1309. /// <param name="lpszRemoteAddress">服务端地址</param>
  1310. /// <param name="usPort">服务端端口</param>
  1311. /// <param name="bAsyncConnect">是否采用异步 Connect</param>
  1312. /// <param name="lpszBindAddress">绑定地址(默认:nullptr,TcpClient/UdpClient -> 不执行绑定操作,UdpCast 绑定 -> 0.0.0.0)</param>
  1313. /// <returns>失败,可通过 HP_Client_GetLastError() 获取错误代码</returns>
  1314. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1315. public static extern bool HP_Client_StartWithBindAddress(IntPtr pClient, string lpszRemoteAddress, ushort usPort, bool bAsyncConnect, string lpszBindAddress);
  1316. /// <summary>
  1317. /// 名称:启动通信组件(并指定绑定地址)
  1318. /// 描述:启动客户端通信组件并连接服务端,启动完成后可开始收发数据
  1319. /// </summary>
  1320. /// <param name="pClient"></param>
  1321. /// <param name="lpszRemoteAddress">服务端地址</param>
  1322. /// <param name="usPort">服务端端口</param>
  1323. /// <param name="bAsyncConnect">是否采用异步 Connect</param>
  1324. /// <param name="lpszBindAddress">绑定地址(默认:nullptr,TcpClient/UdpClient -> 不执行绑定操作,UdpCast 绑定 -> 0.0.0.0)</param>
  1325. /// <param name="usLocalPort">本地端口(默认:0)</param>
  1326. /// <returns>失败,可通过 HP_Client_GetLastError() 获取错误代码</returns>
  1327. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1328. public static extern bool HP_Client_StartWithBindAddressAndLocalPort(IntPtr pClient, string lpszRemoteAddress, ushort usPort, bool bAsyncConnect, string lpszBindAddress, ushort usLocalPort);
  1329. /// <summary>
  1330. /// 关闭客户端通信组件,关闭完成后断开与服务端的连接并释放所有资源
  1331. /// </summary>
  1332. /// <param name="pClient"></param>
  1333. /// <returns>失败,可通过 HP_Client_GetLastError() 获取错误代码</returns>
  1334. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1335. public static extern bool HP_Client_Stop(IntPtr pClient);
  1336. /// <summary>
  1337. /// 用户通过该方法向服务端发送数据
  1338. /// </summary>
  1339. /// <param name="pClient"></param>
  1340. /// <param name="connId">连接 ID(保留参数,目前该参数并未使用)</param>
  1341. /// <param name="pBuffer">发送数据缓冲区</param>
  1342. /// <param name="length">发送数据长度</param>
  1343. /// <returns>失败,可通过 HP_Client_GetLastError() 获取错误代码</returns>
  1344. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1345. public static extern bool HP_Client_Send(IntPtr pClient, byte[] pBuffer, int length);
  1346. /// <summary>
  1347. /// 用户通过该方法向服务端发送数据
  1348. /// </summary>
  1349. /// <param name="pClient"></param>
  1350. /// <param name="connId">连接 ID(保留参数,目前该参数并未使用)</param>
  1351. /// <param name="pBuffer">发送数据缓冲区</param>
  1352. /// <param name="length">发送数据长度</param>
  1353. /// <returns>失败,可通过 HP_Client_GetLastError() 获取错误代码</returns>
  1354. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1355. public static extern bool HP_Client_Send(IntPtr pClient, IntPtr pBuffer, int length);
  1356. /// <summary>
  1357. /// 用户通过该方法向服务端发送数据
  1358. /// </summary>
  1359. /// <param name="pClient"></param>
  1360. /// <param name="pBuffer"></param>
  1361. /// <param name="length"></param>
  1362. /// <param name="iOffset">针对pBuffer的偏移</param>
  1363. /// <returns></returns>
  1364. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1365. public static extern bool HP_Client_SendPart(IntPtr pClient, byte[] pBuffer, int length, int iOffset);
  1366. /// <summary>
  1367. /// 用户通过该方法向服务端发送数据
  1368. /// </summary>
  1369. /// <param name="pClient"></param>
  1370. /// <param name="pBuffer"></param>
  1371. /// <param name="length"></param>
  1372. /// <param name="iOffset">针对pBuffer的偏移</param>
  1373. /// <returns></returns>
  1374. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1375. public static extern bool HP_Client_SendPart(IntPtr pClient, IntPtr pBuffer, int length, int iOffset);
  1376. /// <summary>
  1377. /// 发送多组数据
  1378. /// 向服务端发送多组数据
  1379. /// TCP - 顺序发送所有数据包
  1380. /// UDP - 把所有数据包组合成一个数据包发送(数据包的总长度不能大于设置的 UDP 包最大长度)
  1381. /// </summary>
  1382. /// <param name="pClient"></param>
  1383. /// <param name="pBuffers">发送缓冲区数组</param>
  1384. /// <param name="iCount">发送缓冲区数目</param>
  1385. /// <returns>TRUE.成功,FALSE.失败,可通过 Windows API 函数 ::GetLastError() 获取 Windows 错误代码</returns>
  1386. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1387. public static extern bool HP_Client_SendPackets(IntPtr pClient, WSABUF[] pBuffers, int iCount);
  1388. /// <summary>
  1389. /// 名称:暂停/恢复接收
  1390. /// 描述:暂停/恢复某个连接的数据接收工作
  1391. /// </summary>
  1392. /// <param name="pClient">TRUE - 暂停, FALSE - 恢复</param>
  1393. /// <param name="bPause">TRUE - 暂停, FALSE - 恢复</param>
  1394. /// <returns></returns>
  1395. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1396. public static extern bool HP_Client_PauseReceive(IntPtr pClient, int bPause);
  1397. /******************************************************************************/
  1398. /***************************** Client 属性访问方法 *****************************/
  1399. /// <summary>
  1400. /// 设置连接的附加数据
  1401. /// </summary>
  1402. /// <param name="pClient"></param>
  1403. /// <param name="pExtra"></param>
  1404. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1405. public static extern void HP_Client_SetExtra(IntPtr pClient, IntPtr pExtra);
  1406. /// <summary>
  1407. /// 获取连接的附加数据
  1408. /// </summary>
  1409. /// <param name="pClient"></param>
  1410. /// <returns></returns>
  1411. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1412. public static extern IntPtr HP_Client_GetExtra(IntPtr pClient);
  1413. /// <summary>
  1414. /// 检测是否为安全连接(SSL/HTTPS)
  1415. /// </summary>
  1416. /// <param name="pClient"></param>
  1417. /// <returns></returns>
  1418. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1419. public static extern bool HP_Client_IsSecure(IntPtr pClient);
  1420. /// <summary>
  1421. /// 检查通信组件是否已启动
  1422. /// </summary>
  1423. /// <param name="pClient"></param>
  1424. /// <returns></returns>
  1425. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1426. public static extern bool HP_Client_HasStarted(IntPtr pClient);
  1427. /// <summary>
  1428. /// 查看通信组件当前状态
  1429. /// </summary>
  1430. /// <param name="pClient"></param>
  1431. /// <returns></returns>
  1432. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1433. public static extern ServiceState HP_Client_GetState(IntPtr pClient);
  1434. /// <summary>
  1435. /// 获取最近一次失败操作的错误代码
  1436. /// </summary>
  1437. /// <param name="pClient"></param>
  1438. /// <returns></returns>
  1439. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1440. public static extern SocketError HP_Client_GetLastError(IntPtr pClient);
  1441. /// <summary>
  1442. /// 获取最近一次失败操作的错误描述
  1443. /// </summary>
  1444. /// <param name="pClient"></param>
  1445. /// <returns></returns>
  1446. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1447. public static extern IntPtr HP_Client_GetLastErrorDesc(IntPtr pClient);
  1448. /// <summary>
  1449. /// 获取该组件对象的连接 ID
  1450. /// </summary>
  1451. /// <param name="pClient"></param>
  1452. /// <returns></returns>
  1453. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1454. public static extern IntPtr HP_Client_GetConnectionID(IntPtr pClient);
  1455. /// <summary>
  1456. /// 获取 Client Socket 的地址信息
  1457. /// </summary>
  1458. /// <param name="pClient"></param>
  1459. /// <param name="lpszAddress"></param>
  1460. /// <param name="piAddressLen"></param>
  1461. /// <param name="pusPort"></param>
  1462. /// <returns></returns>
  1463. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1464. public static extern bool HP_Client_GetLocalAddress(IntPtr pClient, [MarshalAs(UnmanagedType.LPStr)] StringBuilder lpszAddress, ref int piAddressLen, ref ushort pusPort);
  1465. /// <summary>
  1466. /// 获取连接的远程主机信息
  1467. /// </summary>
  1468. /// <param name="pClient"></param>
  1469. /// <param name="lpszHost"></param>
  1470. /// <param name="piHostLen"></param>
  1471. /// <param name="pusPort"></param>
  1472. /// <returns></returns>
  1473. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1474. public static extern bool HP_Client_GetRemoteHost(IntPtr pClient, [MarshalAs(UnmanagedType.LPStr)] StringBuilder lpszHost, ref int piHostLen, ref ushort pusPort);
  1475. /// <summary>
  1476. /// 获取连接中未发出数据的长度
  1477. /// </summary>
  1478. /// <param name="pClient"></param>
  1479. /// <param name="piPending"></param>
  1480. /// <returns></returns>
  1481. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1482. public static extern bool HP_Client_GetPendingDataLength(IntPtr pClient, ref int piPending);
  1483. /// <summary>
  1484. /// 获取连接的数据接收状态
  1485. /// </summary>
  1486. /// <param name="pClient"></param>
  1487. /// <param name="pbPaused"></param>
  1488. /// <returns></returns>
  1489. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1490. public static extern bool HP_Client_IsPauseReceive(IntPtr pClient, ref int pbPaused);
  1491. /// <summary>
  1492. /// 检测是否有效连接
  1493. /// </summary>
  1494. /// <param name="pClient"></param>
  1495. /// <returns></returns>
  1496. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1497. public static extern bool HP_Client_IsConnected(IntPtr pClient);
  1498. /// <summary>
  1499. /// 设置内存块缓存池大小(通常设置为 -> PUSH 模型:5 - 10;PULL 模型:10 - 20 )
  1500. /// </summary>
  1501. /// <param name="pClient"></param>
  1502. /// <param name="dwFreeBufferPoolSize"></param>
  1503. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1504. public static extern void HP_Client_SetFreeBufferPoolSize(IntPtr pClient, uint dwFreeBufferPoolSize);
  1505. /// <summary>
  1506. /// 设置内存块缓存池回收阀值(通常设置为内存块缓存池大小的 3 倍)
  1507. /// </summary>
  1508. /// <param name="pClient"></param>
  1509. /// <param name="dwFreeBufferPoolHold"></param>
  1510. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1511. public static extern void HP_Client_SetFreeBufferPoolHold(IntPtr pClient, uint dwFreeBufferPoolHold);
  1512. /// <summary>
  1513. /// 获取内存块缓存池大小
  1514. /// </summary>
  1515. /// <param name="pClient"></param>
  1516. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1517. public static extern uint HP_Client_GetFreeBufferPoolSize(IntPtr pClient);
  1518. /// <summary>
  1519. /// 获取内存块缓存池回收阀值
  1520. /// </summary>
  1521. /// <param name="pClient"></param>
  1522. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1523. public static extern uint HP_Client_GetFreeBufferPoolHold(IntPtr pClient);
  1524. /**********************************************************************************/
  1525. /***************************** TCP Client 操作方法 *****************************/
  1526. /// <summary>
  1527. /// 名称:发送小文件
  1528. /// 描述:向指定连接发送 4096 KB 以下的小文件
  1529. /// </summary>
  1530. /// <param name="pServer"></param>
  1531. /// <param name="lpszFileName">文件路径</param>
  1532. /// <param name="pHead">头部附加数据</param>
  1533. /// <param name="pTail">尾部附加数据</param>
  1534. /// <returns>TRUE.成功 FALSE -- 失败,可通过 Windows API 函数 ::GetLastError() 获取 Windows 错误代码</returns>
  1535. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1536. public static extern bool HP_TcpClient_SendSmallFile(IntPtr pClient, string lpszFileName, ref WSABUF pHead, ref WSABUF pTail);
  1537. /**********************************************************************************/
  1538. /***************************** TCP Client 属性访问方法 *****************************/
  1539. /// <summary>
  1540. /// 设置通信数据缓冲区大小(根据平均通信数据包大小调整设置,通常设置为:(N * 1024) - sizeof(TBufferObj))
  1541. /// </summary>
  1542. /// <param name="pClient"></param>
  1543. /// <param name="dwSocketBufferSize"></param>
  1544. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1545. public static extern void HP_TcpClient_SetSocketBufferSize(IntPtr pClient, uint dwSocketBufferSize);
  1546. /// <summary>
  1547. /// 设置心跳包间隔(毫秒,0 则不发送心跳包)
  1548. /// </summary>
  1549. /// <param name="pClient"></param>
  1550. /// <param name="dwKeepAliveTime"></param>
  1551. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1552. public static extern void HP_TcpClient_SetKeepAliveTime(IntPtr pClient, uint dwKeepAliveTime);
  1553. /// <summary>
  1554. /// 设置心跳确认包检测间隔(毫秒,0 不发送心跳包,如果超过若干次 [默认:WinXP 5 次, Win7 10 次] 检测不到心跳确认包则认为已断线)
  1555. /// </summary>
  1556. /// <param name="pClient"></param>
  1557. /// <param name="dwKeepAliveInterval"></param>
  1558. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1559. public static extern void HP_TcpClient_SetKeepAliveInterval(IntPtr pClient, uint dwKeepAliveInterval);
  1560. /// <summary>
  1561. /// 获取通信数据缓冲区大小
  1562. /// </summary>
  1563. /// <param name="pClient"></param>
  1564. /// <returns></returns>
  1565. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1566. public static extern uint HP_TcpClient_GetSocketBufferSize(IntPtr pClient);
  1567. /// <summary>
  1568. /// 获取心跳检查次数
  1569. /// </summary>
  1570. /// <param name="pClient"></param>
  1571. /// <returns></returns>
  1572. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1573. public static extern uint HP_TcpClient_GetKeepAliveTime(IntPtr pClient);
  1574. /// <summary>
  1575. /// 获取心跳检查间隔
  1576. /// </summary>
  1577. /// <param name="pClient"></param>
  1578. /// <returns></returns>
  1579. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1580. public static extern uint HP_TcpClient_GetKeepAliveInterval(IntPtr pClient);
  1581. /**********************************************************************************/
  1582. /***************************** UDP Client 属性访问方法 *****************************/
  1583. /// <summary>
  1584. /// 设置数据报文最大长度(建议在局域网环境下不超过 1472 字节,在广域网环境下不超过 548 字节)
  1585. /// </summary>
  1586. /// <param name="pClient"></param>
  1587. /// <param name="dwMaxDatagramSize"></param>
  1588. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1589. public static extern void HP_UdpClient_SetMaxDatagramSize(IntPtr pClient, uint dwMaxDatagramSize);
  1590. /// <summary>
  1591. /// 获取数据报文最大长度
  1592. /// </summary>
  1593. /// <param name="pClient"></param>
  1594. /// <returns></returns>
  1595. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1596. public static extern uint HP_UdpClient_GetMaxDatagramSize(IntPtr pClient);
  1597. /// <summary>
  1598. /// 设置监测包尝试次数(0 则不发送监测跳包,如果超过最大尝试次数则认为已断线
  1599. /// </summary>
  1600. /// <param name="pClient"></param>
  1601. /// <param name="dwDetectAttempts"></param>
  1602. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1603. public static extern void HP_UdpClient_SetDetectAttempts(IntPtr pClient, uint dwDetectAttempts);
  1604. /// <summary>
  1605. /// 设置监测包发送间隔(秒,0 不发送监测包)
  1606. /// </summary>
  1607. /// <param name="pClient"></param>
  1608. /// <param name="dwDetectInterval"></param>
  1609. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1610. public static extern void HP_UdpClient_SetDetectInterval(IntPtr pClient, uint dwDetectInterval);
  1611. /// <summary>
  1612. /// 获取心跳检查次数
  1613. /// </summary>
  1614. /// <param name="pClient"></param>
  1615. /// <returns></returns>
  1616. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1617. public static extern uint HP_UdpClient_GetDetectAttempts(IntPtr pClient);
  1618. /// <summary>
  1619. /// 获取心跳检查间隔
  1620. /// </summary>
  1621. /// <param name="pClient"></param>
  1622. /// <returns></returns>
  1623. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1624. public static extern uint HP_UdpClient_GetDetectInterval(IntPtr pClient);
  1625. /**********************************************************************************/
  1626. /****************************** UDP Cast 属性访问方法 ******************************/
  1627. /// <summary>
  1628. /// 设置数据报文最大长度(建议在局域网环境下不超过 1472 字节,在广域网环境下不超过 548 字节
  1629. /// </summary>
  1630. /// <param name="pCast"></param>
  1631. /// <param name="dwMaxDatagramSize"></param>
  1632. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1633. public static extern void HP_UdpCast_SetMaxDatagramSize(IntPtr pCast, uint dwMaxDatagramSize);
  1634. /// <summary>
  1635. /// 获取数据报文最大长度
  1636. /// </summary>
  1637. /// <param name="pCast"></param>
  1638. /// <returns></returns>
  1639. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1640. public static extern uint HP_UdpCast_GetMaxDatagramSize(IntPtr pCast);
  1641. /// <summary>
  1642. /// 获取当前数据报的远程地址信息(通常在 OnReceive 事件中调用)
  1643. /// </summary>
  1644. /// <param name="pCast"></param>
  1645. /// <param name="lpszAddress"></param>
  1646. /// <param name="piAddressLen"></param>
  1647. /// <param name="pusPort"></param>
  1648. /// <returns></returns>
  1649. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1650. public static extern bool HP_UdpCast_GetRemoteAddress(IntPtr pCast, [MarshalAs(UnmanagedType.LPStr)] StringBuilder lpszAddress, ref int piAddressLen, ref ushort pusPort);
  1651. /// <summary>
  1652. /// 设置是否启用地址重用机制(默认:不启用)
  1653. /// </summary>
  1654. /// <param name="pCast"></param>
  1655. /// <param name="bReuseAddress"></param>
  1656. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1657. public static extern void HP_UdpCast_SetReuseAddress(IntPtr pCast, bool bReuseAddress);
  1658. /// <summary>
  1659. /// 检测是否启用地址重用机制
  1660. /// </summary>
  1661. /// <param name="pCast"></param>
  1662. /// <returns></returns>
  1663. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1664. public static extern bool HP_UdpCast_IsReuseAddress(IntPtr pCast);
  1665. /// <summary>
  1666. /// 设置传播模式(组播或广播)
  1667. /// </summary>
  1668. /// <param name="pCast"></param>
  1669. /// <param name="enCastMode"></param>
  1670. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1671. public static extern void HP_UdpCast_SetCastMode(IntPtr pCast, CastMode enCastMode);
  1672. /// <summary>
  1673. /// 获取传播模式
  1674. /// </summary>
  1675. /// <param name="pCast"></param>
  1676. /// <returns></returns>
  1677. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1678. public static extern CastMode HP_UdpCast_GetCastMode(IntPtr pCast);
  1679. /// <summary>
  1680. /// 设置组播报文的 TTL(0 - 255)
  1681. /// </summary>
  1682. /// <param name="pCast"></param>
  1683. /// <param name="iMCTtl"></param>
  1684. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1685. public static extern void HP_UdpCast_SetMultiCastTtl(IntPtr pCast, int iMCTtl);
  1686. /// <summary>
  1687. /// 获取组播报文的 TTL
  1688. /// </summary>
  1689. /// <param name="pCast"></param>
  1690. /// <returns></returns>
  1691. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1692. public static extern int HP_UdpCast_GetMultiCastTtl(IntPtr pCast);
  1693. /// <summary>
  1694. /// 设置是否启用组播环路(TRUE or FALSE)
  1695. /// </summary>
  1696. /// <param name="pCast"></param>
  1697. /// <param name="bMCLoop"></param>
  1698. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1699. public static extern void HP_UdpCast_SetMultiCastLoop(IntPtr pCast, bool bMCLoop);
  1700. /// <summary>
  1701. /// 检测是否启用组播环路
  1702. /// </summary>
  1703. /// <param name="pCast"></param>
  1704. /// <returns></returns>
  1705. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1706. public static extern bool HP_UdpCast_IsMultiCastLoop(IntPtr pCast);
  1707. /**************************************************************************/
  1708. /***************************** Agent 操作方法 *****************************/
  1709. /// <summary>
  1710. /// 启动通信组件
  1711. /// 启动通信代理组件,启动完成后可开始连接远程服务器
  1712. /// </summary>
  1713. /// <param name="pAgent"></param>
  1714. /// <param name="pszBindAddress">监听地址</param>
  1715. /// <param name="bAsyncConnect">是否采用异步 Connect</param>
  1716. /// <returns>失败,可通过 GetLastError() 获取错误代码</returns>
  1717. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1718. public static extern bool HP_Agent_Start(IntPtr pAgent, string pszBindAddress, bool bAsyncConnect);
  1719. /// <summary>
  1720. /// 关闭通信组件
  1721. /// 关闭通信组件,关闭完成后断开所有连接并释放所有资源
  1722. /// </summary>
  1723. /// <param name="pAgent"></param>
  1724. /// <returns>-- 失败,可通过 GetLastError() 获取错误代码</returns>
  1725. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1726. public static extern bool HP_Agent_Stop(IntPtr pAgent);
  1727. /// <summary>
  1728. /// 连接服务器
  1729. /// 连接服务器,连接成功后 IAgentListener 会接收到 OnConnect() 事件
  1730. /// </summary>
  1731. /// <param name="pAgent"></param>
  1732. /// <param name="pszBindAddress">服务端地址</param>
  1733. /// <param name="usPort">服务端端口</param>
  1734. /// <param name="pconnId">传出连接 ID</param>
  1735. /// <returns>失败,可通过 SYS_GetLastError() 获取 Windows 错误代码</returns>
  1736. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1737. public static extern bool HP_Agent_Connect(IntPtr pAgent, string pszBindAddress, ushort usPort, ref IntPtr pconnId);
  1738. /// <summary>
  1739. /// 名称:连接服务器
  1740. /// 描述:连接服务器,连接成功后 IAgentListener 会接收到 OnConnect() / OnHandShake() 事件
  1741. /// </summary>
  1742. /// <param name="pAgent"></param>
  1743. /// <param name="lpszRemoteAddress">服务端地址</param>
  1744. /// <param name="usPort">服务端端口</param>
  1745. /// <param name="pdwConnID">传出连接</param>
  1746. /// <param name="pExtra">连接附加数据(默认:nullptr)</param>
  1747. /// <returns>失败,可通过函数 SYS_GetLastError() 获取 Windows 错误代码</returns>
  1748. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1749. public static extern bool HP_Agent_ConnectWithExtra(IntPtr pAgent, string lpszRemoteAddress, ushort usPort, ref IntPtr pdwConnID, IntPtr pExtra);
  1750. /// <summary>
  1751. /// 名称:连接服务器
  1752. /// 描述:连接服务器,连接成功后 IAgentListener 会接收到 OnConnect() / OnHandShake() 事件
  1753. /// </summary>
  1754. /// <param name="pAgent"></param>
  1755. /// <param name="lpszRemoteAddress">服务端地址</param>
  1756. /// <param name="usPort">服务端端口</param>
  1757. /// <param name="pdwConnID">连接 ID(默认:nullptr,不获取连接 ID)</param>
  1758. /// <param name="usLocalPort">本地端口(默认:0)</param>
  1759. /// <returns>失败,可通过函数 SYS_GetLastError() 获取 Windows 错误代码</returns>
  1760. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1761. public static extern bool HP_Agent_ConnectWithLocalPort(IntPtr pAgent, string lpszRemoteAddress, ushort usPort, ref IntPtr pdwConnID, ushort usLocalPort);
  1762. /// <summary>
  1763. /// 名称:连接服务器
  1764. /// 描述:连接服务器,连接成功后 IAgentListener 会接收到 OnConnect() / OnHandShake() 事件
  1765. /// </summary>
  1766. /// <param name="pAgent"></param>
  1767. /// <param name="lpszRemoteAddress">服务端地址</param>
  1768. /// <param name="usPort">服务端端口</param>
  1769. /// <param name="pdwConnID">连接 ID(默认:nullptr,不获取连接 ID)</param>
  1770. /// <param name="lpszLocalAddress">本地地址(默认:nullptr,使用 Start() 方法中绑定的地址)</param>
  1771. /// <returns>失败,可通过函数 SYS_GetLastError() 获取 Windows 错误代码</returns>
  1772. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1773. public static extern bool HP_Agent_ConnectWithLocalAddress(IntPtr pAgent, string lpszRemoteAddress, ushort usPort, ref IntPtr pdwConnID, string lpszLocalAddress);
  1774. /// <summary>
  1775. /// 名称:连接服务器
  1776. /// 描述:连接服务器,连接成功后 IAgentListener 会接收到 OnConnect() / OnHandShake() 事件
  1777. /// </summary>
  1778. /// <param name="pAgent"></param>
  1779. /// <param name="lpszRemoteAddress">服务端地址</param>
  1780. /// <param name="usPort">服务端端口</param>
  1781. /// <param name="pdwConnID">连接 ID(默认:nullptr,不获取连接 ID)</param>
  1782. /// <param name="pExtra">连接附加数据(默认:nullptr)</param>
  1783. /// <param name="usLocalPort">本地端口(默认:0)</param>
  1784. /// <returns></returns>
  1785. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1786. public static extern bool HP_Agent_ConnectWithExtraAndLocalPort(IntPtr pAgent, string lpszRemoteAddress, ushort usPort, ref IntPtr pdwConnID, IntPtr pExtra, ushort usLocalPort);
  1787. /// <summary>
  1788. /// 名称:连接服务器
  1789. /// 描述:连接服务器,连接成功后 IAgentListener 会接收到 OnConnect() / OnHandShake() 事件
  1790. /// </summary>
  1791. /// <param name="pAgent"></param>
  1792. /// <param name="lpszRemoteAddress">服务端地址</param>
  1793. /// <param name="usPort">服务端端口</param>
  1794. /// <param name="pdwConnID">连接 ID(默认:nullptr,不获取连接 ID)</param>
  1795. /// <param name="pExtra">连接附加数据(默认:nullptr)</param>
  1796. /// <param name="usLocalPort">本地端口(默认:0)</param>
  1797. /// <param name="lpszLocalAddress">本地地址(默认:nullptr,使用 Start() 方法中绑定的地址)</param>
  1798. /// <returns></returns>
  1799. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1800. public static extern bool HP_Agent_ConnectWithExtraAndLocalAddressPort(IntPtr pAgent, string lpszRemoteAddress, ushort usPort, ref IntPtr pdwConnID, IntPtr pExtra, ushort usLocalPort, string lpszLocalAddress);
  1801. /// <summary>
  1802. /// 发送数据
  1803. /// 用户通过该方法向指定连接发送数据
  1804. /// </summary>
  1805. /// <param name="pAgent"></param>
  1806. /// <param name="connId">连接 ID</param>
  1807. /// <param name="pBuffer">发送数据缓冲区</param>
  1808. /// <param name="length">发送数据长度</param>
  1809. /// <returns></returns>
  1810. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1811. public static extern bool HP_Agent_Send(IntPtr pAgent, IntPtr connId, byte[] pBuffer, int length);
  1812. /// <summary>
  1813. /// 发送数据
  1814. /// 用户通过该方法向指定连接发送数据
  1815. /// </summary>
  1816. /// <param name="pAgent"></param>
  1817. /// <param name="connId">连接 ID</param>
  1818. /// <param name="pBuffer">发送数据缓冲区</param>
  1819. /// <param name="length">发送数据长度</param>
  1820. /// <returns></returns>
  1821. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1822. public static extern bool HP_Agent_Send(IntPtr pAgent, IntPtr connId, IntPtr pBuffer, int length);
  1823. /// <summary>
  1824. /// 发送数据
  1825. /// 用户通过该方法向指定连接发送数据
  1826. /// </summary>
  1827. /// <param name="pAgent"></param>
  1828. /// <param name="connId"></param>
  1829. /// <param name="pBuffer"></param>
  1830. /// <param name="length"></param>
  1831. /// <param name="iOffset">针对pBuffer的偏移</param>
  1832. /// <returns></returns>
  1833. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1834. public static extern bool HP_Agent_SendPart(IntPtr pAgent, IntPtr connId, byte[] pBuffer, int length, int iOffset);
  1835. /// <summary>
  1836. /// 发送数据
  1837. /// 用户通过该方法向指定连接发送数据
  1838. /// </summary>
  1839. /// <param name="pAgent"></param>
  1840. /// <param name="connId"></param>
  1841. /// <param name="pBuffer"></param>
  1842. /// <param name="length"></param>
  1843. /// <param name="iOffset">针对pBuffer的偏移</param>
  1844. /// <returns></returns>
  1845. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1846. public static extern bool HP_Agent_SendPart(IntPtr pAgent, IntPtr connId, IntPtr pBuffer, int length, int iOffset);
  1847. /// <summary>
  1848. /// 发送多组数据
  1849. /// 向指定连接发送多组数据
  1850. /// TCP - 顺序发送所有数据包
  1851. /// UDP - 把所有数据包组合成一个数据包发送(数据包的总长度不能大于设置的 UDP 包最大长度)
  1852. /// </summary>
  1853. /// <param name="pAgent"></param>
  1854. /// <param name="connId">连接 ID</param>
  1855. /// <param name="pBuffers">发送缓冲区数组</param>
  1856. /// <param name="iCount">发送缓冲区数目</param>
  1857. /// <returns>TRUE.成功,FALSE .失败,可通过 Windows API 函数 ::GetLastError() 获取 Windows 错误代码</returns>
  1858. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1859. public static extern bool HP_Agent_SendPackets(IntPtr pAgent, IntPtr connId, WSABUF[] pBuffers, int iCount);
  1860. /// <summary>
  1861. /// 名称:暂停/恢复接收
  1862. /// 描述:暂停/恢复某个连接的数据接收工作
  1863. /// </summary>
  1864. /// <param name="pAgent"></param>
  1865. /// <param name="dwConnID"></param>
  1866. /// <param name="bPause">TRUE - 暂停, FALSE - 恢复</param>
  1867. /// <returns></returns>
  1868. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1869. public static extern bool HP_Agent_PauseReceive(IntPtr pAgent, IntPtr dwConnID, bool bPause);
  1870. /// <summary>
  1871. /// 断开某个连接
  1872. /// </summary>
  1873. /// <param name="pAgent"></param>
  1874. /// <param name="connId">连接 ID</param>
  1875. /// <param name="bForce">是否强制断开连接</param>
  1876. /// <returns></returns>
  1877. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1878. public static extern bool HP_Agent_Disconnect(IntPtr pAgent, IntPtr connId, bool bForce);
  1879. /// <summary>
  1880. /// 断开超过指定时长的连接
  1881. /// </summary>
  1882. /// <param name="pAgent"></param>
  1883. /// <param name="dwPeriod">时长(毫秒)</param>
  1884. /// <param name="bForce">是否强制断开连接</param>
  1885. /// <returns></returns>
  1886. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1887. public static extern bool HP_Agent_DisconnectLongConnections(IntPtr pAgent, uint dwPeriod, bool bForce);
  1888. /// <summary>
  1889. /// 断开超过指定时长的静默连接
  1890. /// </summary>
  1891. /// <param name="pServer"></param>
  1892. /// <param name="dwPeriod">时长(毫秒)</param>
  1893. /// <param name="bForce">是否强制断开连接</param>
  1894. /// <returns></returns>
  1895. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1896. public static extern bool HP_Agent_DisconnectSilenceConnections(IntPtr pAgent, uint dwPeriod, bool bForce);
  1897. /******************************************************************************/
  1898. /***************************** Agent 操作方法 *****************************/
  1899. /// <summary>
  1900. /// 名称:发送小文件
  1901. /// 描述:向指定连接发送 4096 KB 以下的小文件
  1902. /// </summary>
  1903. /// <param name="pServer"></param>
  1904. /// <param name="connId">连接 ID</param>
  1905. /// <param name="lpszFileName">文件路径</param>
  1906. /// <param name="pHead">头部附加数据</param>
  1907. /// <param name="pTail">尾部附加数据</param>
  1908. /// <returns>TRUE.成功 FALSE -- 失败,可通过 Windows API 函数 ::GetLastError() 获取 Windows 错误代码</returns>
  1909. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1910. public static extern bool HP_TcpAgent_SendSmallFile(IntPtr pAgent, IntPtr connId, string lpszFileName, ref WSABUF pHead, ref WSABUF pTail);
  1911. /******************************************************************************/
  1912. /***************************** Agent 属性访问方法 *****************************/
  1913. /// <summary>
  1914. /// 设置数据发送策略
  1915. /// </summary>
  1916. /// <param name="pAgent"></param>
  1917. /// <param name="enSendPolicy"></param>
  1918. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1919. public static extern void HP_Agent_SetSendPolicy(IntPtr pAgent, SendPolicy enSendPolicy);
  1920. /// <summary>
  1921. /// 获取数据发送策略
  1922. /// </summary>
  1923. /// <param name="pAgent"></param>
  1924. /// <returns></returns>
  1925. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1926. public static extern SendPolicy HP_Agent_GetSendPolicy(IntPtr pAgent);
  1927. /// <summary>
  1928. /// 获取 OnSend 事件同步策略
  1929. /// </summary>
  1930. /// <param name="pServer"></param>
  1931. /// <returns></returns>
  1932. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1933. public static extern OnSendSyncPolicy HP_Agent_GetOnSendSyncPolicy(IntPtr pAgent);
  1934. /// <summary>
  1935. /// 设置 OnSend 事件同步策略(默认:OSSP_NONE,不同步
  1936. /// </summary>
  1937. /// <param name="pServer"></param>
  1938. /// <param name="syncPolicy"></param>
  1939. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1940. public static extern void HP_Agent_SetOnSendSyncPolicy(IntPtr pAgent, OnSendSyncPolicy syncPolicy);
  1941. /// <summary>
  1942. /// 设置连接的附加数据
  1943. /// 是否为连接绑定附加数据或者绑定什么样的数据,均由应用程序只身决定
  1944. /// </summary>
  1945. /// <param name="pAgent"></param>
  1946. /// <param name="connId">连接 ID</param>
  1947. /// <param name="pExtra">数据</param>
  1948. /// <returns>FALSE -- 失败(无效的连接 ID)</returns>
  1949. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1950. public static extern bool HP_Agent_SetConnectionExtra(IntPtr pAgent, IntPtr connId, IntPtr pExtra);
  1951. /// <summary>
  1952. /// 获取连接的附加数据
  1953. /// 是否为连接绑定附加数据或者绑定什么样的数据,均由应用程序只身决定
  1954. /// </summary>
  1955. /// <param name="pAgent"></param>
  1956. /// <param name="connId"></param>
  1957. /// <param name="pExtra"></param>
  1958. /// <returns></returns>
  1959. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1960. public static extern bool HP_Agent_GetConnectionExtra(IntPtr pAgent, IntPtr connId, ref IntPtr pExtra);
  1961. /// <summary>
  1962. /// 检测是否为安全连接(SSL/HTTPS)
  1963. /// </summary>
  1964. /// <param name="pAgent"></param>
  1965. /// <returns></returns>
  1966. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1967. public static extern bool HP_Agent_IsSecure(IntPtr pAgent);
  1968. /// <summary>
  1969. /// 检查通信组件是否已启动
  1970. /// </summary>
  1971. /// <param name="pAgent"></param>
  1972. /// <returns></returns>
  1973. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1974. public static extern bool HP_Agent_HasStarted(IntPtr pAgent);
  1975. /// <summary>
  1976. /// 查看通信组件当前状态
  1977. /// </summary>
  1978. /// <param name="pAgent"></param>
  1979. /// <returns></returns>
  1980. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1981. public static extern ServiceState HP_Agent_GetState(IntPtr pAgent);
  1982. /// <summary>
  1983. /// 获取连接数
  1984. /// </summary>
  1985. /// <param name="pAgent"></param>
  1986. /// <returns></returns>
  1987. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1988. public static extern uint HP_Agent_GetConnectionCount(IntPtr pAgent);
  1989. /// <summary>
  1990. /// 获取所有连接的 CONNID
  1991. /// </summary>
  1992. /// <param name="pServer"></param>
  1993. /// <param name="pIDs"></param>
  1994. /// <param name="pdwCount"></param>
  1995. /// <returns></returns>
  1996. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  1997. public static extern bool HP_Agent_GetAllConnectionIDs(IntPtr pAgent, IntPtr[] pIDs, ref uint pdwCount);
  1998. /// <summary>
  1999. /// 获取某个连接时长(毫秒)
  2000. /// </summary>
  2001. /// <param name="pAgent"></param>
  2002. /// <param name="connId"></param>
  2003. /// <param name="pdwPeriod"></param>
  2004. /// <returns></returns>
  2005. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2006. public static extern bool HP_Agent_GetConnectPeriod(IntPtr pAgent, IntPtr connId, ref uint pdwPeriod);
  2007. /// <summary>
  2008. /// 获取某个连接静默时间(毫秒)
  2009. /// </summary>
  2010. /// <param name="pServer"></param>
  2011. /// <param name="connId"></param>
  2012. /// <param name="pdwPeriod"></param>
  2013. /// <returns></returns>
  2014. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2015. public static extern bool HP_Agent_GetSilencePeriod(IntPtr pAgent, IntPtr connId, ref uint pdwPeriod);
  2016. /// <summary>
  2017. /// 获取某个连接的本地地址信息
  2018. /// </summary>
  2019. /// <param name="pAgent"></param>
  2020. /// <param name="connId"></param>
  2021. /// <param name="lpszAddress"></param>
  2022. /// <param name="piAddressLen"></param>
  2023. /// <param name="pusPort"></param>
  2024. /// <returns></returns>
  2025. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2026. public static extern bool HP_Agent_GetLocalAddress(IntPtr pAgent, IntPtr connId, [MarshalAs(UnmanagedType.LPStr)] StringBuilder lpszAddress, ref int piAddressLen, ref ushort pusPort);
  2027. /// <summary>
  2028. /// 获取某个连接的远程地址信息
  2029. /// </summary>
  2030. /// <param name="pAgent"></param>
  2031. /// <param name="connId"></param>
  2032. /// <param name="lpszAddress"></param>
  2033. /// <param name="piAddressLen"></param>
  2034. /// <param name="pusPort"></param>
  2035. /// <returns></returns>
  2036. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2037. public static extern bool HP_Agent_GetRemoteAddress(IntPtr pAgent, IntPtr connId, [MarshalAs(UnmanagedType.LPStr)] StringBuilder lpszAddress, ref int piAddressLen, ref ushort pusPort);
  2038. /// <summary>
  2039. /// 获取某个连接的远程主机信息
  2040. /// </summary>
  2041. /// <param name="pAgent"></param>
  2042. /// <param name="dwConnID"></param>
  2043. /// <param name="lpszAddress"></param>
  2044. /// <param name="piHostLen"></param>
  2045. /// <param name="pusPort"></param>
  2046. /// <returns></returns>
  2047. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2048. public static extern bool HP_Agent_GetRemoteHost(IntPtr pAgent, IntPtr dwConnID, [MarshalAs(UnmanagedType.LPStr)]StringBuilder lpszAddress, ref int piHostLen, ref ushort pusPort);
  2049. /// <summary>
  2050. /// 获取最近一次失败操作的错误代码
  2051. /// </summary>
  2052. /// <param name="pAgent"></param>
  2053. /// <returns></returns>
  2054. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2055. public static extern SocketError HP_Agent_GetLastError(IntPtr pAgent);
  2056. /// <summary>
  2057. /// 获取最近一次失败操作的错误描述
  2058. /// </summary>
  2059. /// <param name="pAgent"></param>
  2060. /// <returns></returns>
  2061. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2062. public static extern IntPtr HP_Agent_GetLastErrorDesc(IntPtr pAgent);
  2063. /// <summary>
  2064. /// 获取连接中未发出数据的长度
  2065. /// </summary>
  2066. /// <param name="pAgent"></param>
  2067. /// <param name="connId"></param>
  2068. /// <param name="piPending"></param>
  2069. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2070. public static extern bool HP_Agent_GetPendingDataLength(IntPtr pAgent, IntPtr connId, ref int piPending);
  2071. /// <summary>
  2072. /// 获取连接的数据接收状态
  2073. /// </summary>
  2074. /// <param name="pAgent"></param>
  2075. /// <param name="dwConnID"></param>
  2076. /// <param name="pbPaused"></param>
  2077. /// <returns></returns>
  2078. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2079. public static extern bool HP_Agent_IsPauseReceive(IntPtr pAgent, IntPtr dwConnID, ref int pbPaused);
  2080. /// <summary>
  2081. /// 检测是否有效连接
  2082. /// </summary>
  2083. /// <param name="pAgent"></param>
  2084. /// <param name="dwConnID"></param>
  2085. /// <returns></returns>
  2086. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2087. public static extern bool HP_Agent_IsConnected(IntPtr pAgent, IntPtr dwConnID);
  2088. /// <summary>
  2089. /// 设置 Socket 缓存对象锁定时间(毫秒,在锁定期间该 Socket 缓存对象不能被获取使用)
  2090. /// </summary>
  2091. /// <param name="pAgent"></param>
  2092. /// <param name="dwFreeSocketObjLockTime"></param>
  2093. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2094. public static extern void HP_Agent_SetFreeSocketObjLockTime(IntPtr pAgent, uint dwFreeSocketObjLockTime);
  2095. /// <summary>
  2096. /// 设置 Socket 缓存池大小(通常设置为平均并发连接数量的 1/3 - 1/2)
  2097. /// </summary>
  2098. /// <param name="pAgent"></param>
  2099. /// <param name="dwFreeSocketObjPool"></param>
  2100. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2101. public static extern void HP_Agent_SetFreeSocketObjPool(IntPtr pAgent, uint dwFreeSocketObjPool);
  2102. /// <summary>
  2103. /// 设置内存块缓存池大小(通常设置为 Socket 缓存池大小的 2 - 3 倍)
  2104. /// </summary>
  2105. /// <param name="pAgent"></param>
  2106. /// <param name="dwFreeBufferObjPool"></param>
  2107. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2108. public static extern void HP_Agent_SetFreeBufferObjPool(IntPtr pAgent, uint dwFreeBufferObjPool);
  2109. /// <summary>
  2110. /// 设置 Socket 缓存池回收阀值(通常设置为 Socket 缓存池大小的 3 倍)
  2111. /// </summary>
  2112. /// <param name="pAgent"></param>
  2113. /// <param name="dwFreeSocketObjHold"></param>
  2114. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2115. public static extern void HP_Agent_SetFreeSocketObjHold(IntPtr pAgent, uint dwFreeSocketObjHold);
  2116. /// <summary>
  2117. /// 设置内存块缓存池回收阀值(通常设置为内存块缓存池大小的 3 倍)
  2118. /// </summary>
  2119. /// <param name="pAgent"></param>
  2120. /// <param name="dwFreeBufferObjHold"></param>
  2121. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2122. public static extern void HP_Agent_SetFreeBufferObjHold(IntPtr pAgent, uint dwFreeBufferObjHold);
  2123. /// <summary>
  2124. /// 设置最大连接数(组件会根据设置值预分配内存,因此需要根据实际情况设置,不宜过大)
  2125. /// </summary>
  2126. /// <param name="pAgent"></param>
  2127. /// <param name="dwMaxConnectionCount"></param>
  2128. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2129. public static extern void HP_Agent_SetMaxConnectionCount(IntPtr pAgent, uint dwMaxConnectionCount);
  2130. /// <summary>
  2131. /// 设置工作线程数量(通常设置为 2 * CPU + 2)
  2132. /// </summary>
  2133. /// <param name="pAgent"></param>
  2134. /// <param name="dwWorkerThreadCount"></param>
  2135. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2136. public static extern void HP_Agent_SetWorkerThreadCount(IntPtr pAgent, uint dwWorkerThreadCount);
  2137. /// <summary>
  2138. /// 设置是否标记静默时间(设置为 TRUE 时 DisconnectSilenceConnections() 和 GetSilencePeriod() 才有效,默认:FALSE)
  2139. /// </summary>
  2140. /// <param name="pServer"></param>
  2141. /// <param name="bMarkSilence"></param>
  2142. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2143. public static extern void HP_Agent_SetMarkSilence(IntPtr pAgent, bool bMarkSilence);
  2144. /// <summary>
  2145. /// 获取 Socket 缓存对象锁定时间
  2146. /// </summary>
  2147. /// <param name="pAgent"></param>
  2148. /// <returns></returns>
  2149. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2150. public static extern uint HP_Agent_GetFreeSocketObjLockTime(IntPtr pAgent);
  2151. /// <summary>
  2152. /// 获取 Socket 缓存池大小
  2153. /// </summary>
  2154. /// <param name="pAgent"></param>
  2155. /// <returns></returns>
  2156. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2157. public static extern uint HP_Agent_GetFreeSocketObjPool(IntPtr pAgent);
  2158. /// <summary>
  2159. /// 获取内存块缓存池大小
  2160. /// </summary>
  2161. /// <param name="pAgent"></param>
  2162. /// <returns></returns>
  2163. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2164. public static extern uint HP_Agent_GetFreeBufferObjPool(IntPtr pAgent);
  2165. /// <summary>
  2166. /// 获取 Socket 缓存池回收阀值
  2167. /// </summary>
  2168. /// <param name="pAgent"></param>
  2169. /// <returns></returns>
  2170. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2171. public static extern uint HP_Agent_GetFreeSocketObjHold(IntPtr pAgent);
  2172. /// <summary>
  2173. /// 获取内存块缓存池回收阀值
  2174. /// </summary>
  2175. /// <param name="pAgent"></param>
  2176. /// <returns></returns>
  2177. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2178. public static extern uint HP_Agent_GetFreeBufferObjHold(IntPtr pAgent);
  2179. /// <summary>
  2180. /// 获取最大连接数
  2181. /// </summary>
  2182. /// <param name="pAgent"></param>
  2183. /// <returns></returns>
  2184. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2185. public static extern uint HP_Agent_GetMaxConnectionCount(IntPtr pAgent);
  2186. /// <summary>
  2187. /// 获取工作线程数量
  2188. /// </summary>
  2189. /// <param name="pAgent"></param>
  2190. /// <returns></returns>
  2191. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2192. public static extern uint HP_Agent_GetWorkerThreadCount(IntPtr pAgent);
  2193. /// <summary>
  2194. /// 检测是否标记静默时间
  2195. /// </summary>
  2196. /// <param name="pServer"></param>
  2197. /// <returns></returns>
  2198. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2199. public static extern bool HP_Agent_IsMarkSilence(IntPtr pAgent);
  2200. /**********************************************************************************/
  2201. /***************************** TCP Agent 属性访问方法 *****************************/
  2202. /// <summary>
  2203. /// 置是否启用地址重用机制(默认:不启用)
  2204. /// </summary>
  2205. /// <param name="pAgent"></param>
  2206. /// <param name="bReuseAddress"></param>
  2207. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2208. public static extern void HP_TcpAgent_SetReuseAddress(IntPtr pAgent, bool bReuseAddress);
  2209. /// <summary>
  2210. /// 检测是否启用地址重用机制
  2211. /// </summary>
  2212. /// <param name="pAgent"></param>
  2213. /// <returns></returns>
  2214. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2215. public static extern bool HP_TcpAgent_IsReuseAddress(IntPtr pAgent);
  2216. /// <summary>
  2217. /// 设置通信数据缓冲区大小(根据平均通信数据包大小调整设置,通常设置为 1024 的倍数)
  2218. /// </summary>
  2219. /// <param name="pAgent"></param>
  2220. /// <param name="dwSocketBufferSize"></param>
  2221. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2222. public static extern void HP_TcpAgent_SetSocketBufferSize(IntPtr pAgent, uint dwSocketBufferSize);
  2223. /// <summary>
  2224. /// 设置心跳包间隔(毫秒,0 则不发送心跳包)
  2225. /// </summary>
  2226. /// <param name="pAgent"></param>
  2227. /// <param name="dwKeepAliveTime"></param>
  2228. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2229. public static extern void HP_TcpAgent_SetKeepAliveTime(IntPtr pAgent, uint dwKeepAliveTime);
  2230. /// <summary>
  2231. /// 设置心跳确认包检测间隔(毫秒,0 不发送心跳包,如果超过若干次 [默认:WinXP 5 次, Win7 10 次] 检测不到心跳确认包则认为已断线)
  2232. /// </summary>
  2233. /// <param name="pAgent"></param>
  2234. /// <param name="dwKeepAliveInterval"></param>
  2235. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2236. public static extern void HP_TcpAgent_SetKeepAliveInterval(IntPtr pAgent, uint dwKeepAliveInterval);
  2237. /// <summary>
  2238. /// 获取通信数据缓冲区大小
  2239. /// </summary>
  2240. /// <param name="pAgent"></param>
  2241. /// <returns></returns>
  2242. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2243. public static extern uint HP_TcpAgent_GetSocketBufferSize(IntPtr pAgent);
  2244. /// <summary>
  2245. /// 获取心跳检查次数
  2246. /// </summary>
  2247. /// <param name="pAgent"></param>
  2248. /// <returns></returns>
  2249. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2250. public static extern uint HP_TcpAgent_GetKeepAliveTime(IntPtr pAgent);
  2251. /// <summary>
  2252. /// 获取心跳检查间隔
  2253. /// </summary>
  2254. /// <param name="pAgent"></param>
  2255. /// <returns></returns>
  2256. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2257. public static extern uint HP_TcpAgent_GetKeepAliveInterval(IntPtr pAgent);
  2258. /***************************************************************************************/
  2259. /***************************** TCP Pull Server 组件操作方法 *****************************/
  2260. /// <summary>
  2261. /// 抓取数据
  2262. /// 用户通过该方法从 Socket 组件中抓取数据
  2263. /// </summary>
  2264. /// <param name="pServer"></param>
  2265. /// <param name="connId">连接 ID</param>
  2266. /// <param name="pBuffer">数据抓取缓冲区</param>
  2267. /// <param name="length">抓取数据长度</param>
  2268. /// <returns></returns>
  2269. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2270. public static extern FetchResult HP_TcpPullServer_Fetch(IntPtr pServer, IntPtr connId, IntPtr pBuffer, int length);
  2271. /// <summary>
  2272. /// 窥探数据(不会移除缓冲区数据)
  2273. /// 描述:用户通过该方法从 Socket 组件中窥探数据
  2274. /// </summary>
  2275. /// <param name="pServer"></param>
  2276. /// <param name="connId">连接 ID</param>
  2277. /// <param name="pBuffer">窥探缓冲区</param>
  2278. /// <param name="length">窥探数据长度</param>
  2279. /// <returns></returns>
  2280. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2281. public static extern FetchResult HP_TcpPullServer_Peek(IntPtr pServer, IntPtr connId, IntPtr pBuffer, int length);
  2282. /***************************************************************************************/
  2283. /***************************** TCP Pull Server 属性访问方法 *****************************/
  2284. /***************************************************************************************/
  2285. /***************************** TCP Pull Client 组件操作方法 *****************************/
  2286. /// <summary>
  2287. /// 抓取数据
  2288. /// 用户通过该方法从 Socket 组件中抓取数据
  2289. /// </summary>
  2290. /// <param name="pClient"></param>
  2291. /// <param name="connId">连接 ID</param>
  2292. /// <param name="pBuffer">数据抓取缓冲区</param>
  2293. /// <param name="length">抓取数据长度</param>
  2294. /// <returns></returns>
  2295. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2296. public static extern FetchResult HP_TcpPullClient_Fetch(IntPtr pClient, IntPtr pBuffer, int length);
  2297. /// <summary>
  2298. /// 名称:窥探数据(不会移除缓冲区数据)
  2299. /// 描述:用户通过该方法从 Socket 组件中窥探数据
  2300. /// </summary>
  2301. /// <param name="pClient"></param>
  2302. /// <param name="connId">连接 ID</param>
  2303. /// <param name="pBuffer">数据抓取缓冲区</param>
  2304. /// <param name="length">抓取数据长度</param>
  2305. /// <returns></returns>
  2306. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2307. public static extern FetchResult HP_TcpPullClient_Peek(IntPtr pClient, IntPtr pBuffer, int length);
  2308. /***************************************************************************************/
  2309. /***************************** TCP Pull Client 属性访问方法 *****************************/
  2310. /***************************************************************************************/
  2311. /***************************** TCP Pull Agent 组件操作方法 *****************************/
  2312. /// <summary>
  2313. /// 抓取数据
  2314. /// 用户通过该方法从 Socket 组件中抓取数据
  2315. /// </summary>
  2316. /// <param name="pAgent"></param>
  2317. /// <param name="connId">连接 ID</param>
  2318. /// <param name="pBuffer">数据抓取缓冲区</param>
  2319. /// <param name="length">抓取数据长度</param>
  2320. /// <returns></returns>
  2321. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2322. public static extern FetchResult HP_TcpPullAgent_Fetch(IntPtr pAgent, IntPtr connId, IntPtr pBuffer, int length);
  2323. /// <summary>
  2324. /// 名称:窥探数据(不会移除缓冲区数据)
  2325. /// 描述:用户通过该方法从 Socket 组件中窥探数据
  2326. /// </summary>
  2327. /// <param name="pAgent"></param>
  2328. /// <param name="connId">连接 ID</param>
  2329. /// <param name="pBuffer">数据抓取缓冲区</param>
  2330. /// <param name="length">抓取数据长度</param>
  2331. /// <returns></returns>
  2332. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2333. public static extern FetchResult HP_TcpPullAgent_Peek(IntPtr pAgent, IntPtr connId, IntPtr pBuffer, int length);
  2334. /***************************************************************************************/
  2335. /***************************** TCP Pull Agent 属性访问方法 *****************************/
  2336. /***************************************************************************************/
  2337. /***************************************************************************************/
  2338. /***************************** TCP Pack Server 组件操作方法 *****************************/
  2339. /***************************************************************************************/
  2340. /***************************** TCP Pack Server 属性访问方法 *****************************/
  2341. /// <summary>
  2342. /// 设置数据包最大长度(有效数据包最大长度不能超过 4194303/0x3FFFFF 字节,默认:262144/0x40000)
  2343. /// </summary>
  2344. /// <param name="pServer"></param>
  2345. /// <param name="dwMaxPackSize">有效数据包最大长度不能超过 4194303/0x3FFFFF 字节,默认:262144/0x40000</param>
  2346. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2347. public static extern void HP_TcpPackServer_SetMaxPackSize(IntPtr pServer, uint dwMaxPackSize);
  2348. /// <summary>
  2349. /// 设置包头标识(有效包头标识取值范围 0 ~ 1023/0x3FF,当包头标识为 0 时不校验包头,默认:0)
  2350. /// </summary>
  2351. /// <param name="pServer"></param>
  2352. /// <param name="usPackHeaderFlag">有效包头标识取值范围 0 ~ 1023/0x3FF,当包头标识为 0 时不校验包头,默认:0</param>
  2353. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2354. public static extern void HP_TcpPackServer_SetPackHeaderFlag(IntPtr pServer, ushort usPackHeaderFlag);
  2355. /// <summary>
  2356. /// 获取数据包最大长度
  2357. /// </summary>
  2358. /// <param name="pServer"></param>
  2359. /// <returns></returns>
  2360. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2361. public static extern uint HP_TcpPackServer_GetMaxPackSize(IntPtr pServer);
  2362. /// <summary>
  2363. /// 获取包头标识
  2364. /// </summary>
  2365. /// <param name="pServer"></param>
  2366. /// <returns></returns>
  2367. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2368. public static extern ushort HP_TcpPackServer_GetPackHeaderFlag(IntPtr pServer);
  2369. /***************************************************************************************/
  2370. /***************************** TCP Pack Agent 组件操作方法 *****************************/
  2371. /***************************************************************************************/
  2372. /***************************** TCP Pack Agent 属性访问方法 *****************************/
  2373. /// <summary>
  2374. /// 设置数据包最大长度(有效数据包最大长度不能超过 524287/0x7FFFF 字节,默认:262144/0x40000)
  2375. /// </summary>
  2376. /// <param name="pServer"></param>
  2377. /// <param name="dwMaxPackSize">有效数据包最大长度不能超过 524287/0x7FFFF 字节,默认:262144/0x40000</param>
  2378. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2379. public static extern void HP_TcpPackAgent_SetMaxPackSize(IntPtr pAgent, uint dwMaxPackSize);
  2380. /// <summary>
  2381. /// 设置包头标识(有效包头标识取值范围 0 ~ 8191/0x1FFF,当包头标识为 0 时不校验包头,默认:0)
  2382. /// </summary>
  2383. /// <param name="pServer"></param>
  2384. /// <param name="usPackHeaderFlag">有效包头标识取值范围 0 ~ 8191/0x1FFF,当包头标识为 0 时不校验包头,默认:0</param>
  2385. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2386. public static extern void HP_TcpPackAgent_SetPackHeaderFlag(IntPtr pAgent, ushort usPackHeaderFlag);
  2387. /// <summary>
  2388. /// 获取数据包最大长度
  2389. /// </summary>
  2390. /// <param name="pServer"></param>
  2391. /// <returns></returns>
  2392. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2393. public static extern uint HP_TcpPackAgent_GetMaxPackSize(IntPtr pAgent);
  2394. /// <summary>
  2395. /// 获取包头标识
  2396. /// </summary>
  2397. /// <param name="pServer"></param>
  2398. /// <returns></returns>
  2399. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2400. public static extern ushort HP_TcpPackAgent_GetPackHeaderFlag(IntPtr pAgent);
  2401. /***************************************************************************************/
  2402. /***************************** TCP Pack Client 组件操作方法 *****************************/
  2403. /***************************************************************************************/
  2404. /***************************** TCP Pack Client 属性访问方法 *****************************/
  2405. /// <summary>
  2406. /// 设置数据包最大长度(有效数据包最大长度不能超过 524287/0x7FFFF 字节,默认:262144/0x40000)
  2407. /// </summary>
  2408. /// <param name="pServer"></param>
  2409. /// <param name="dwMaxPackSize">有效数据包最大长度不能超过 524287/0x7FFFF 字节,默认:262144/0x40000</param>
  2410. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2411. public static extern void HP_TcpPackClient_SetMaxPackSize(IntPtr pClient, uint dwMaxPackSize);
  2412. /// <summary>
  2413. /// 设置包头标识(有效包头标识取值范围 0 ~ 8191/0x1FFF,当包头标识为 0 时不校验包头,默认:0)
  2414. /// </summary>
  2415. /// <param name="pServer"></param>
  2416. /// <param name="usPackHeaderFlag">有效包头标识取值范围 0 ~ 8191/0x1FFF,当包头标识为 0 时不校验包头,默认:0</param>
  2417. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2418. public static extern void HP_TcpPackClient_SetPackHeaderFlag(IntPtr pClient, ushort usPackHeaderFlag);
  2419. /// <summary>
  2420. /// 获取数据包最大长度
  2421. /// </summary>
  2422. /// <param name="pServer"></param>
  2423. /// <returns></returns>
  2424. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2425. public static extern uint HP_TcpPackClient_GetMaxPackSize(IntPtr pClient);
  2426. /// <summary>
  2427. /// 获取包头标识
  2428. /// </summary>
  2429. /// <param name="pServer"></param>
  2430. /// <returns></returns>
  2431. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2432. public static extern ushort HP_TcpPackClient_GetPackHeaderFlag(IntPtr pClient);
  2433. /***************************************************************************************/
  2434. /*************************************** 其它方法 ***************************************/
  2435. /// <summary>
  2436. /// 获取 HPSocket 版本号(4 个字节分别为:主版本号,子版本号,修正版本号,构建编号)
  2437. /// </summary>
  2438. /// <returns></returns>
  2439. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2440. public static extern uint HP_GetHPSocketVersion();
  2441. /// <summary>
  2442. /// 获取版本号
  2443. /// </summary>
  2444. /// <returns></returns>
  2445. public static string GetHPSocketVersion()
  2446. {
  2447. /*
  2448. var ver = BitConverter.GetBytes(HP_GetHPSocketVersion());
  2449. var major = ver[3];
  2450. var minor = ver[2];
  2451. var revision = ver[1];
  2452. var build = ver[0];*/
  2453. uint ver = HP_GetHPSocketVersion();
  2454. var major = ver >> 24;
  2455. var minor = (ver << 8) >> 24;
  2456. var revision = (ver << 16) >> 24;
  2457. var build = (ver << 24) >> 24;
  2458. return string.Format("{0}.{1}.{2}_{3}", major, minor, revision, build);
  2459. }
  2460. /// <summary>
  2461. /// 获取错误描述文本
  2462. /// </summary>
  2463. /// <param name="enCode"></param>
  2464. /// <returns></returns>
  2465. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2466. public static extern IntPtr HP_GetSocketErrorDesc(SocketError enCode);
  2467. /// <summary>
  2468. /// 调用系统的 ::GetLastError() 方法获取系统错误代码
  2469. /// </summary>
  2470. /// <returns></returns>
  2471. public static int SYS_GetLastError()
  2472. {
  2473. return Marshal.GetLastWin32Error();
  2474. }
  2475. /// <summary>
  2476. /// 调用系统的 ::WSAGetLastError() 方法获取通信错误代码
  2477. /// </summary>
  2478. /// <returns></returns>
  2479. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2480. public static extern int SYS_WSAGetLastError();
  2481. /// <summary>
  2482. /// 调用系统的 setsockopt()
  2483. /// </summary>
  2484. /// <param name="sock"></param>
  2485. /// <param name="level"></param>
  2486. /// <param name="name"></param>
  2487. /// <param name="val"></param>
  2488. /// <param name="len"></param>
  2489. /// <returns></returns>
  2490. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2491. public static extern int SYS_SetSocketOption(IntPtr sock, int level, int name, IntPtr val, int len);
  2492. /// <summary>
  2493. /// 调用系统的 getsockopt()
  2494. /// </summary>
  2495. /// <param name="sock"></param>
  2496. /// <param name="level"></param>
  2497. /// <param name="name"></param>
  2498. /// <param name="val"></param>
  2499. /// <param name="len"></param>
  2500. /// <returns></returns>
  2501. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2502. public static extern int SYS_GetSocketOption(IntPtr sock, int level, int name, IntPtr val, ref int len);
  2503. /// <summary>
  2504. /// 调用系统的 ioctlsocket()
  2505. /// </summary>
  2506. /// <param name="sock"></param>
  2507. /// <param name="cmd"></param>
  2508. /// <param name="arg"></param>
  2509. /// <returns></returns>
  2510. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2511. public static extern int SYS_IoctlSocket(IntPtr sock, long cmd, IntPtr arg);
  2512. /// <summary>
  2513. /// 调用系统的 ::WSAIoctl()
  2514. /// </summary>
  2515. /// <param name="sock"></param>
  2516. /// <param name="dwIoControlCode"></param>
  2517. /// <param name="lpvInBuffer"></param>
  2518. /// <param name="cbInBuffer"></param>
  2519. /// <param name="lpvOutBuffer"></param>
  2520. /// <param name="cbOutBuffer"></param>
  2521. /// <param name="lpcbBytesReturned"></param>
  2522. /// <returns></returns>
  2523. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2524. public static extern int SYS_WSAIoctl(IntPtr sock, uint dwIoControlCode, IntPtr lpvInBuffer, uint cbInBuffer,
  2525. IntPtr lpvOutBuffer, uint cbOutBuffer, uint lpcbBytesReturned);
  2526. /// <summary>
  2527. /// 设置 socket 选项:IPPROTO_TCP -> TCP_NODELAY
  2528. /// </summary>
  2529. /// <param name="sock"></param>
  2530. /// <param name="bNoDelay"></param>
  2531. /// <returns></returns>
  2532. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2533. public static extern int SYS_SSO_NoDelay(IntPtr sock, bool bNoDelay);
  2534. /// <summary>
  2535. /// 设置 socket 选项:SOL_SOCKET -> SO_DONTLINGER
  2536. /// </summary>
  2537. /// <param name="sock"></param>
  2538. /// <param name="bDont"></param>
  2539. /// <returns></returns>
  2540. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2541. public static extern int SYS_SSO_DontLinger(IntPtr sock, bool bDont);
  2542. /// <summary>
  2543. /// 设置 socket 选项:SOL_SOCKET -> SO_LINGER
  2544. /// </summary>
  2545. /// <param name="sock"></param>
  2546. /// <param name="l_onoff"></param>
  2547. /// <param name="l_linger"></param>
  2548. /// <returns></returns>
  2549. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2550. public static extern int SYS_SSO_Linger(IntPtr sock, ushort l_onoff, ushort l_linger);
  2551. /// <summary>
  2552. /// 设置 socket 选项:SOL_SOCKET -> SO_RCVBUF
  2553. /// </summary>
  2554. /// <param name="sock"></param>
  2555. /// <param name="size"></param>
  2556. /// <returns></returns>
  2557. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2558. public static extern int SYS_SSO_RecvBuffSize(IntPtr sock, int size);
  2559. /// <summary>
  2560. /// 设置 socket 选项:SOL_SOCKET -> SO_SNDBUF
  2561. /// </summary>
  2562. /// <param name="sock"></param>
  2563. /// <param name="size"></param>
  2564. /// <returns></returns>
  2565. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2566. public static extern int SYS_SSO_SendBuffSize(IntPtr sock, int size);
  2567. /// <summary>
  2568. /// 设置 socket 选项:SOL_SOCKET -> SO_REUSEADDR
  2569. /// </summary>
  2570. /// <param name="sock"></param>
  2571. /// <param name="bReuse"></param>
  2572. /// <returns></returns>
  2573. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2574. public static extern int SYS_SSO_ReuseAddress(IntPtr sock, bool bReuse);
  2575. /// <summary>
  2576. /// 获取 SOCKET 本地地址信息
  2577. /// </summary>
  2578. /// <param name="pSocket"></param>
  2579. /// <param name="lpszAddress"></param>
  2580. /// <param name="piAddressLen">传入传出值,大小最好在222.222.222.222的长度以上</param>
  2581. /// <param name="pusPort"></param>
  2582. /// <returns></returns>
  2583. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2584. public static extern bool SYS_GetSocketLocalAddress(IntPtr pSocket, [MarshalAs(UnmanagedType.LPStr)] StringBuilder lpszAddress, ref int piAddressLen, ref ushort pusPort);
  2585. /// <summary>
  2586. /// 获取 SOCKET 远程地址信息
  2587. /// </summary>
  2588. /// <param name="pSocket"></param>
  2589. /// <param name="lpszAddress"></param>
  2590. /// <param name="piAddressLen">传入传出值,大小最好在222.222.222.222的长度以上</param>
  2591. /// <param name="pusPort"></param>
  2592. /// <returns></returns>
  2593. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2594. public static extern bool SYS_GetSocketRemoteAddress(IntPtr pSocket, [MarshalAs(UnmanagedType.LPStr)] StringBuilder lpszAddress, ref int piAddressLen, ref ushort pusPort);
  2595. /// <summary>
  2596. /// 枚举主机 IP 地址
  2597. /// 不要用,未测试
  2598. /// 不要用,未测试
  2599. /// 不要用,未测试
  2600. /// </summary>
  2601. /// <param name="lpszHost"></param>
  2602. /// <param name="enType"></param>
  2603. /// <param name="lpppIPAddr"></param>
  2604. /// <param name="piIPAddrCount"></param>
  2605. /// <returns></returns>
  2606. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2607. public static extern bool SYS_EnumHostIPAddresses(string lpszHost, IPAddrType enType, ref IntPtr lpppIPAddr, ref int piIPAddrCount);
  2608. /// <summary>
  2609. /// 释放 HP_LPTIPAddr
  2610. /// </summary>
  2611. /// <param name="lppIPAddr"></param>
  2612. /// <returns></returns>
  2613. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2614. public static extern bool SYS_FreeHostIPAddresses(IntPtr lppIPAddr);
  2615. /*
  2616. * 已删除
  2617. /// <summary>
  2618. /// 获取 IPv4 地址
  2619. /// </summary>
  2620. /// <param name="lpszAddress"></param>
  2621. /// <returns></returns>
  2622. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2623. public static extern uint SYS_GetIPv4InAddr(string lpszAddress);
  2624. */
  2625. /// <summary>
  2626. /// 检查字符串是否符合 IP 地址格式
  2627. /// </summary>
  2628. /// <param name="lpszAddress"></param>
  2629. /// <param name="penType"></param>
  2630. /// <returns></returns>
  2631. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2632. public static extern bool SYS_IsIPAddress(string lpszAddress, ref IPAddrType penType);
  2633. /// <summary>
  2634. /// 通过主机名获取 IP 地址
  2635. /// </summary>
  2636. /// <param name="lpszHost"></param>
  2637. /// <param name="lpszIP"></param>
  2638. /// <param name="piIPLenth"></param>
  2639. /// <param name="penType"></param>
  2640. /// <returns></returns>
  2641. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2642. public static extern bool SYS_GetIPAddress(string lpszHost, [MarshalAs(UnmanagedType.LPStr)] StringBuilder lpszIP, ref int piIPLenth, ref IPAddrType penType);
  2643. /*
  2644. * 已删除
  2645. /// <summary>
  2646. /// 通过主机名获取最优的 IP 地址
  2647. /// </summary>
  2648. /// <param name="lpszHost"></param>
  2649. /// <param name="pulAddr"></param>
  2650. /// <returns></returns>
  2651. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2652. public static extern bool SYS_GetOptimalIPByHostName(string lpszHost, ref uint pulAddr);
  2653. */
  2654. /// <summary>
  2655. /// 64 位网络字节序转主机字节序
  2656. /// </summary>
  2657. /// <param name="value"></param>
  2658. /// <returns></returns>
  2659. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2660. public static extern ulong SYS_NToH64(ulong value);
  2661. /// <summary>
  2662. /// 64 位主机字节序转网络字节序
  2663. /// </summary>
  2664. /// <param name="value"></param>
  2665. /// <returns></returns>
  2666. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2667. public static extern ulong SYS_HToN64(ulong value);
  2668. /// <summary>
  2669. /// 分配内存
  2670. /// </summary>
  2671. /// <param name="value"></param>
  2672. /// <returns></returns>
  2673. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2674. public static extern IntPtr SYS_Malloc(int value);
  2675. /// <summary>
  2676. /// 重新分配内存
  2677. /// </summary>
  2678. /// <param name="p"></param>
  2679. /// <param name="value"></param>
  2680. /// <returns></returns>
  2681. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2682. public static extern IntPtr SYS_Realloc(IntPtr p, int value);
  2683. /// <summary>
  2684. /// 释放内存
  2685. /// </summary>
  2686. /// <param name="p"></param>
  2687. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2688. public static extern void SYS_Free(IntPtr p);
  2689. /// <summary>
  2690. /// 创建 HP_UdpArqServer 对象
  2691. /// </summary>
  2692. /// <param name="pListener"></param>
  2693. /// <returns></returns>
  2694. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2695. public static extern IntPtr Create_HP_UdpArqServer(IntPtr pListener);
  2696. /// <summary>
  2697. /// 创建 HP_UdpArqClient 对象
  2698. /// </summary>
  2699. /// <param name="pListener"></param>
  2700. /// <returns></returns>
  2701. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2702. public static extern IntPtr Create_HP_UdpArqClient(IntPtr pListener);
  2703. /// <summary>
  2704. /// 销毁 HP_UdpArqServer 对象
  2705. /// </summary>
  2706. /// <param name="pServer"></param>
  2707. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2708. public static extern void Destroy_HP_UdpArqServer(IntPtr pServer);
  2709. /// <summary>
  2710. /// 销毁 HP_UdpArqClient 对象
  2711. /// </summary>
  2712. /// <param name="pClient"></param>
  2713. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2714. public static extern void Destroy_HP_UdpArqClient(IntPtr pClient);
  2715. /// <summary>
  2716. /// 创建 HP_UdpArqServerListener 对象
  2717. /// </summary>
  2718. /// <returns></returns>
  2719. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2720. public static extern IntPtr Create_HP_UdpArqServerListener();
  2721. /// <summary>
  2722. /// 创建 HP_UdpArqClientListener 对象
  2723. /// </summary>
  2724. /// <returns></returns>
  2725. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2726. public static extern IntPtr Create_HP_UdpArqClientListener();
  2727. /// <summary>
  2728. /// 销毁 HP_UdpArqServerListener 对象
  2729. /// </summary>
  2730. /// <param name="pListener"></param>
  2731. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2732. public static extern void Destroy_HP_UdpArqServerListener(IntPtr pListener);
  2733. /// <summary>
  2734. /// 销毁 HP_UdpArqClientListener 对象
  2735. /// </summary>
  2736. /// <param name="pListener"></param>
  2737. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2738. public static extern void Destroy_HP_UdpArqClientListener(IntPtr pListener);
  2739. /**********************************************************************************/
  2740. /*************************** UDP ARQ Server 属性访问方法 ***************************/
  2741. /// <summary>
  2742. /// 设置是否开启 nodelay 模式(默认:FALSE,不开启)
  2743. /// </summary>
  2744. /// <param name="pServer"></param>
  2745. /// <param name="bNoDelay"></param>
  2746. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2747. public static extern void HP_UdpArqServer_SetNoDelay(IntPtr pServer, bool bNoDelay);
  2748. /// <summary>
  2749. /// 设置是否关闭拥塞控制(默认:FALSE,不关闭)
  2750. /// </summary>
  2751. /// <param name="pServer"></param>
  2752. /// <param name="bTurnOff"></param>
  2753. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2754. public static extern void HP_UdpArqServer_SetTurnoffCongestCtrl(IntPtr pServer, bool bTurnOff);
  2755. /// <summary>
  2756. /// 设置数据刷新间隔(毫秒,默认:20)
  2757. /// </summary>
  2758. /// <param name="pServer"></param>
  2759. /// <param name="dwFlushInterval"></param>
  2760. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2761. public static extern void HP_UdpArqServer_SetFlushInterval(IntPtr pServer, uint dwFlushInterval);
  2762. /// <summary>
  2763. /// 设置快速重传 ACK 跨越次数(默认:0,关闭快速重传)
  2764. /// </summary>
  2765. /// <param name="pServer"></param>
  2766. /// <param name="dwResendByAcks"></param>
  2767. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2768. public static extern void HP_UdpArqServer_SetResendByAcks(IntPtr pServer, uint dwResendByAcks);
  2769. /// <summary>
  2770. /// 设置发送窗口大小(数据包数量,默认:128)
  2771. /// </summary>
  2772. /// <param name="pServer"></param>
  2773. /// <param name="dwSendWndSize"></param>
  2774. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2775. public static extern void HP_UdpArqServer_SetSendWndSize(IntPtr pServer, uint dwSendWndSize);
  2776. /// <summary>
  2777. /// 设置接收窗口大小(数据包数量,默认:512)
  2778. /// </summary>
  2779. /// <param name="pServer"></param>
  2780. /// <param name="dwRecvWndSize"></param>
  2781. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2782. public static extern void HP_UdpArqServer_SetRecvWndSize(IntPtr pServer, uint dwRecvWndSize);
  2783. /// <summary>
  2784. /// 设置最小重传超时时间(毫秒,默认:30)
  2785. /// </summary>
  2786. /// <param name="pServer"></param>
  2787. /// <param name="dwMinRto"></param>
  2788. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2789. public static extern void HP_UdpArqServer_SetMinRto(IntPtr pServer, uint dwMinRto);
  2790. /// <summary>
  2791. /// 设置最大传输单元(默认:0,与 SetMaxDatagramSize() 一致)
  2792. /// </summary>
  2793. /// <param name="pServer"></param>
  2794. /// <param name="dwMaxTransUnit"></param>
  2795. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2796. public static extern void HP_UdpArqServer_SetMaxTransUnit(IntPtr pServer, uint dwMaxTransUnit);
  2797. /// <summary>
  2798. /// 设置最大数据包大小(默认:4096)
  2799. /// </summary>
  2800. /// <param name="pServer"></param>
  2801. /// <param name="dwMaxMessageSize"></param>
  2802. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2803. public static extern void HP_UdpArqServer_SetMaxMessageSize(IntPtr pServer, uint dwMaxMessageSize);
  2804. /// <summary>
  2805. /// 设置握手超时时间(毫秒,默认:5000)
  2806. /// </summary>
  2807. /// <param name="pServer"></param>
  2808. /// <param name="dwHandShakeTimeout"></param>
  2809. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2810. public static extern void HP_UdpArqServer_SetHandShakeTimeout(IntPtr pServer, uint dwHandShakeTimeout);
  2811. /// <summary>
  2812. /// 检测是否开启 nodelay 模式
  2813. /// </summary>
  2814. /// <param name="pServer"></param>
  2815. /// <returns></returns>
  2816. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2817. public static extern bool HP_UdpArqServer_IsNoDelay(IntPtr pServer);
  2818. /// <summary>
  2819. /// 检测是否关闭拥塞控制
  2820. /// </summary>
  2821. /// <param name="pServer"></param>
  2822. /// <returns></returns>
  2823. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2824. public static extern bool HP_UdpArqServer_IsTurnoffCongestCtrl(IntPtr pServer);
  2825. /// <summary>
  2826. /// 获取数据刷新间隔
  2827. /// </summary>
  2828. /// <param name="pServer"></param>
  2829. /// <returns></returns>
  2830. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2831. public static extern uint HP_UdpArqServer_GetFlushInterval(IntPtr pServer);
  2832. /// <summary>
  2833. /// 获取快速重传 ACK 跨越次数
  2834. /// </summary>
  2835. /// <param name="pServer"></param>
  2836. /// <returns></returns>
  2837. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2838. public static extern uint HP_UdpArqServer_GetResendByAcks(IntPtr pServer);
  2839. /// <summary>
  2840. /// 获取发送窗口大小
  2841. /// </summary>
  2842. /// <param name="pServer"></param>
  2843. /// <returns></returns>
  2844. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2845. public static extern uint HP_UdpArqServer_GetSendWndSize(IntPtr pServer);
  2846. /// <summary>
  2847. /// 获取接收窗口大小
  2848. /// </summary>
  2849. /// <param name="pServer"></param>
  2850. /// <returns></returns>
  2851. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2852. public static extern uint HP_UdpArqServer_GetRecvWndSize(IntPtr pServer);
  2853. /// <summary>
  2854. /// 获取最小重传超时时间
  2855. /// </summary>
  2856. /// <param name="pServer"></param>
  2857. /// <returns></returns>
  2858. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2859. public static extern uint HP_UdpArqServer_GetMinRto(IntPtr pServer);
  2860. /// <summary>
  2861. /// 获取最大传输单元
  2862. /// </summary>
  2863. /// <param name="pServer"></param>
  2864. /// <returns></returns>
  2865. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2866. public static extern uint HP_UdpArqServer_GetMaxTransUnit(IntPtr pServer);
  2867. /// <summary>
  2868. /// 获取最大数据包大小
  2869. /// </summary>
  2870. /// <param name="pServer"></param>
  2871. /// <returns></returns>
  2872. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2873. public static extern uint HP_UdpArqServer_GetMaxMessageSize(IntPtr pServer);
  2874. /// <summary>
  2875. /// 获取握手超时时间
  2876. /// </summary>
  2877. /// <param name="pServer"></param>
  2878. /// <returns></returns>
  2879. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2880. public static extern uint HP_UdpArqServer_GetHandShakeTimeout(IntPtr pServer);
  2881. /// <summary>
  2882. /// 获取等待发送包数量
  2883. /// </summary>
  2884. /// <param name="pServer"></param>
  2885. /// <param name="dwConnId"></param>
  2886. /// <param name="piCount"></param>
  2887. /// <returns></returns>
  2888. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2889. public static extern bool HP_UdpArqServer_GetWaitingSendMessageCount(IntPtr pServer, IntPtr dwConnId, ref int piCount);
  2890. /**********************************************************************************/
  2891. /*************************** UDP ARQ Client 属性访问方法 ***************************/
  2892. /// <summary>
  2893. /// 设置是否开启 nodelay 模式(默认:FALSE,不开启)
  2894. /// </summary>
  2895. /// <param name="pClient"></param>
  2896. /// <param name="bNoDelay"></param>
  2897. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2898. public static extern void HP_UdpArqClient_SetNoDelay(IntPtr pClient, bool bNoDelay);
  2899. /// <summary>
  2900. /// 设置是否关闭拥塞控制(默认:FALSE,不关闭)
  2901. /// </summary>
  2902. /// <param name="pClient"></param>
  2903. /// <param name="bTurnOff"></param>
  2904. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2905. public static extern void HP_UdpArqClient_SetTurnoffCongestCtrl(IntPtr pClient, bool bTurnOff);
  2906. /// <summary>
  2907. /// 设置数据刷新间隔(毫秒,默认:20)
  2908. /// </summary>
  2909. /// <param name="pClient"></param>
  2910. /// <param name="dwFlushInterval"></param>
  2911. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2912. public static extern void HP_UdpArqClient_SetFlushInterval(IntPtr pClient, uint dwFlushInterval);
  2913. /// <summary>
  2914. /// 设置快速重传 ACK 跨越次数(默认:0,关闭快速重传)
  2915. /// </summary>
  2916. /// <param name="pClient"></param>
  2917. /// <param name="dwResendByAcks"></param>
  2918. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2919. public static extern void HP_UdpArqClient_SetResendByAcks(IntPtr pClient, uint dwResendByAcks);
  2920. /// <summary>
  2921. /// 设置发送窗口大小(数据包数量,默认:128)
  2922. /// </summary>
  2923. /// <param name="pClient"></param>
  2924. /// <param name="dwSendWndSize"></param>
  2925. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2926. public static extern void HP_UdpArqClient_SetSendWndSize(IntPtr pClient, uint dwSendWndSize);
  2927. /// <summary>
  2928. /// 设置接收窗口大小(数据包数量,默认:512)
  2929. /// </summary>
  2930. /// <param name="pClient"></param>
  2931. /// <param name="dwRecvWndSize"></param>
  2932. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2933. public static extern void HP_UdpArqClient_SetRecvWndSize(IntPtr pClient, uint dwRecvWndSize);
  2934. /// <summary>
  2935. /// 设置最小重传超时时间(毫秒,默认:30)
  2936. /// </summary>
  2937. /// <param name="pClient"></param>
  2938. /// <param name="dwMinRto"></param>
  2939. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2940. public static extern void HP_UdpArqClient_SetMinRto(IntPtr pClient, uint dwMinRto);
  2941. /// <summary>
  2942. /// 设置最大传输单元(默认:0,与 SetMaxDatagramSize() 一致)
  2943. /// </summary>
  2944. /// <param name="pClient"></param>
  2945. /// <param name="dwMaxTransUnit"></param>
  2946. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2947. public static extern void HP_UdpArqClient_SetMaxTransUnit(IntPtr pClient, uint dwMaxTransUnit);
  2948. /// <summary>
  2949. /// 设置最大数据包大小(默认:4096)
  2950. /// </summary>
  2951. /// <param name="pClient"></param>
  2952. /// <param name="dwMaxMessageSize"></param>
  2953. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2954. public static extern void HP_UdpArqClient_SetMaxMessageSize(IntPtr pClient, uint dwMaxMessageSize);
  2955. /// <summary>
  2956. /// 设置握手超时时间(毫秒,默认:5000)
  2957. /// </summary>
  2958. /// <param name="pClient"></param>
  2959. /// <param name="dwHandShakeTimeout"></param>
  2960. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2961. public static extern void HP_UdpArqClient_SetHandShakeTimeout(IntPtr pClient, uint dwHandShakeTimeout);
  2962. /// <summary>
  2963. /// 检测是否开启 nodelay 模式
  2964. /// </summary>
  2965. /// <param name="pClient"></param>
  2966. /// <returns></returns>
  2967. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2968. public static extern bool HP_UdpArqClient_IsNoDelay(IntPtr pClient);
  2969. /// <summary>
  2970. /// 检测是否关闭拥塞控制
  2971. /// </summary>
  2972. /// <param name="pClient"></param>
  2973. /// <returns></returns>
  2974. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2975. public static extern bool HP_UdpArqClient_IsTurnoffCongestCtrl(IntPtr pClient);
  2976. /// <summary>
  2977. /// 获取数据刷新间隔
  2978. /// </summary>
  2979. /// <param name="pClient"></param>
  2980. /// <returns></returns>
  2981. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2982. public static extern uint HP_UdpArqClient_GetFlushInterval(IntPtr pClient);
  2983. /// <summary>
  2984. /// 获取快速重传 ACK 跨越次数
  2985. /// </summary>
  2986. /// <param name="pClient"></param>
  2987. /// <returns></returns>
  2988. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2989. public static extern uint HP_UdpArqClient_GetResendByAcks(IntPtr pClient);
  2990. /// <summary>
  2991. /// 获取发送窗口大小
  2992. /// </summary>
  2993. /// <param name="pClient"></param>
  2994. /// <returns></returns>
  2995. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  2996. public static extern uint HP_UdpArqClient_GetSendWndSize(IntPtr pClient);
  2997. /// <summary>
  2998. /// 获取接收窗口大小
  2999. /// </summary>
  3000. /// <param name="pClient"></param>
  3001. /// <returns></returns>
  3002. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  3003. public static extern uint HP_UdpArqClient_GetRecvWndSize(IntPtr pClient);
  3004. /// <summary>
  3005. /// 获取最小重传超时时间
  3006. /// </summary>
  3007. /// <param name="pClient"></param>
  3008. /// <returns></returns>
  3009. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  3010. public static extern uint HP_UdpArqClient_GetMinRto(IntPtr pClient);
  3011. /// <summary>
  3012. /// 获取最大传输单元
  3013. /// </summary>
  3014. /// <param name="pClient"></param>
  3015. /// <returns></returns>
  3016. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  3017. public static extern uint HP_UdpArqClient_GetMaxTransUnit(IntPtr pClient);
  3018. /// <summary>
  3019. /// 获取最大数据包大小
  3020. /// </summary>
  3021. /// <param name="pClient"></param>
  3022. /// <returns></returns>
  3023. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  3024. public static extern uint HP_UdpArqClient_GetMaxMessageSize(IntPtr pClient);
  3025. /// <summary>
  3026. /// 获取握手超时时间
  3027. /// </summary>
  3028. /// <param name="pClient"></param>
  3029. /// <returns></returns>
  3030. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  3031. public static extern uint HP_UdpArqClient_GetHandShakeTimeout(IntPtr pClient);
  3032. /// <summary>
  3033. /// 获取等待发送包数量
  3034. /// </summary>
  3035. /// <param name="pClient"></param>
  3036. /// <param name="piCount"></param>
  3037. /// <returns></returns>
  3038. [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
  3039. public static extern bool HP_UdpArqClient_GetWaitingSendMessageCount(IntPtr pClient, ref int piCount);
  3040. }