1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Runtime.InteropServices;
- using System.Text;
- using HPSocketCS;
- namespace HPSocketCS
- {
- public interface IServer
- {
- }
- public class ServerEvent
- {
- public delegate HandleResult OnSendEventHandler(IServer sender, IntPtr connId, byte[] bytes);
- public delegate HandleResult OnReceiveEventHandler(IServer sender, IntPtr connId, byte[] bytes);
- public delegate HandleResult OnPointerDataReceiveEventHandler(IServer sender, IntPtr connId, IntPtr pData, int length);
- public delegate HandleResult OnCloseEventHandler(IServer sender, IntPtr connId, SocketOperation enOperation, int errorCode);
- public delegate HandleResult OnShutdownEventHandler(IServer sender);
- public delegate HandleResult OnPrepareListenEventHandler(IServer sender, IntPtr soListen);
- /// <summary>
- /// 连接进入
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="connId"></param>
- /// <param name="pClient">如果为 TCP 连接,pClient为 SOCKET 句柄;如果为 UDP 连接,pClient为 SOCKADDR 指针;</param>
- /// <returns></returns>
- public delegate HandleResult OnAcceptEventHandler(IServer sender, IntPtr connId, IntPtr pClient);
- public delegate HandleResult OnHandShakeEventHandler(IServer sender, IntPtr connId);
- }
- public interface IClient
- {
- }
- public class ClientEvent
- {
- public delegate HandleResult OnPrepareConnectEventHandler(IClient sender, IntPtr socket);
- public delegate HandleResult OnConnectEventHandler(IClient sender);
- public delegate HandleResult OnSendEventHandler(IClient sender, byte[] bytes);
- public delegate HandleResult OnReceiveEventHandler(IClient sender, byte[] bytes);
- public delegate HandleResult OnPointerDataReceiveEventHandler(IClient sender, IntPtr pData, int length);
- public delegate HandleResult OnCloseEventHandler(IClient sender, SocketOperation enOperation, int errorCode);
- public delegate HandleResult OnHandShakeEventHandler(IClient sender);
- }
- /// <summary>
- /// 通信组件服务状态,用程序可以通过通信组件的 GetState() 方法获取组件当前服务状态
- /// </summary>
- public enum ServiceState
- {
- /// <summary>
- /// 正在启动
- /// </summary>
- Starting = 0,
- /// <summary>
- /// 已经启动
- /// </summary>
- Started = 1,
- /// <summary>
- /// 正在停止
- /// </summary>
- Stopping = 2,
- /// <summary>
- /// 已经启动
- /// </summary>
- Stopped = 3,
- }
- /// <summary>
- /// Socket 操作类型,应用程序的 OnErrror() 事件中通过该参数标识是哪种操作导致的错误
- /// </summary>
- public enum SocketOperation
- {
- Unknown = 0, // Unknown
- Accept = 1, // Accept
- Connect = 2, // Connect
- Send = 3, // Send
- Receive = 4, // Receive
- Close = 5, // Receive
- };
- /// <summary>
- /// 事件通知处理结果,事件通知的返回值,不同的返回值会影响通信组件的后续行为
- /// </summary>
- public enum HandleResult
- {
- /// <summary>
- /// 成功
- /// </summary>
- Ok = 0,
- /// <summary>
- /// 忽略
- /// </summary>
- Ignore = 1,
- /// <summary>
- /// 错误
- /// </summary>
- Error = 2,
- };
- /// <summary>
- /// 名称:操作结果代码
- /// 描述:组件 Start() / Stop() 方法执行失败时,可通过 GetLastError() 获取错误代码
- /// </summary>
- public enum SocketError
- {
- /// <summary>
- /// 成功
- /// </summary>
- Ok = 0,
- /// <summary>
- /// 当前状态不允许操作
- /// </summary>
- IllegalState = 1,
- /// <summary>
- /// 非法参数
- /// </summary>
- InvalidParam = 2,
- /// <summary>
- /// 创建 SOCKET 失败
- /// </summary>
- SocketCreate = 3,
- /// <summary>
- /// 绑定 SOCKET 失败
- /// </summary>
- SocketBind = 4,
- /// <summary>
- /// 设置 SOCKET 失败
- /// </summary>
- SocketPrepare = 5,
- /// <summary>
- /// 监听 SOCKET 失败
- /// </summary>
- SocketListen = 6,
- /// <summary>
- /// 创建完成端口失败
- /// </summary>
- CPCreate = 7,
- /// <summary>
- /// 创建工作线程失败
- /// </summary>
- WorkerThreadCreate = 8,
- /// <summary>
- /// 创建监测线程失败
- /// </summary>
- DetectThreadCreate = 9,
- /// <summary>
- /// 绑定完成端口失败
- /// </summary>
- SocketAttachToCP = 10,
- /// <summary>
- /// 连接服务器失败
- /// </summary>
- ConnectServer = 11,
- /// <summary>
- /// 网络错误
- /// </summary>
- Network = 12,
- /// <summary>
- /// 数据处理错误
- /// </summary>
- DataProc = 13,
- /// <summary>
- /// 数据发送失败
- /// </summary>
- DataSend = 14,
- /***** SSL Socket 扩展操作结果代码 *****/
- /// <summary>
- /// SSL 环境未就绪
- /// </summary>
- SSLEnvNotReady = 101,
- };
- /// <summary>
- /// 数据抓取结果,数据抓取操作的返回值
- /// </summary>
- public enum FetchResult
- {
- /// <summary>
- /// 成功
- /// </summary>
- Ok = 0,
- /// <summary>
- /// 抓取长度过大
- /// </summary>
- LengthTooLong = 1,
- /// <summary>
- /// 找不到 ConnID 对应的数据
- /// </summary>
- DataNotFound = 2,
- };
- /// <summary>
- /// 发送策略
- /// </summary>
- public enum SendPolicy
- {
- /// <summary>
- /// 打包模式(默认)
- /// </summary>
- Pack = 0,
- /// <summary>
- /// 安全模式
- /// </summary>
- Safe = 1,
- /// <summary>
- /// 直接模式
- /// </summary>
- Direct = 2,
- };
- /// <summary>
- /// OnSend 事件同步策略
- /// Server 组件和 Agent 组件的 OnSend 事件同步策略
- /// </summary>
- public enum OnSendSyncPolicy
- {
- /// <summary>
- /// 不同步(默认) :不同步 OnSend 事件,此时可能同时触发 OnReceive 和 OnClose 事件
- /// </summary>
- OSSP_NONE = 0,
- /// <summary>
- /// 同步 OnClose :只同步 OnClose 事件,此时可能同时触发 OnReceive 事件
- /// </summary>
- OSSP_CLOSE = 1,
- /// <summary>
- /// 同步 OnReceive :(只用于 TCP 组件)同步 OnReceive 和 OnClose 事件,此处不可能同时触发 OnReceive 或 OnClose 事件
- /// </summary>
- OSSP_RECEIVE = 2,
- }
- /// <summary>
- /// 播送模式 UDP 组件的播送模式(组播或广播)
- /// </summary>
- public enum CastMode
- {
- /// <summary>
- /// 组播
- /// </summary>
- Multicast = 0,
- /// <summary>
- /// 广播
- /// </summary>
- Broadcast = 1,
- }
- /// <summary>
- /// 名称:IP 地址类型
- /// 描述:IP 地址类型枚举值
- /// </summary>
- public enum IPAddrType
- {
- /// <summary>
- /// 所有
- /// </summary>
- All = 0,
- /// <summary>
- /// IPv4
- /// </summary>
- IPV4 = 1,
- /// <summary>
- /// IPv6
- /// </summary>
- IPV6 = 2,
- /// <summary>
- /// 其他
- /// </summary>
- Other = 100,
- }
- /// <summary>
- /// 接收状态
- /// </summary>
- public enum ReceiveState : int
- {
- /// <summary>
- /// 未知
- /// </summary>
- Unknown = -1,
- /// <summary>
- /// 唤醒状态
- /// </summary>
- Resume = 0,
- /// <summary>
- /// 暂停状态
- /// </summary>
- Pause = 1,
- }
- /****************************************************/
- /************** sockaddr结构体,udp服务器时OnAccept最后个参数可转化 **************/
- [StructLayout(LayoutKind.Sequential)]
- public struct in_addr
- {
- public ulong S_addr;
- }
- //[StructLayout(LayoutKind.Sequential)]
- //public struct in_addr
- //{
- // public byte s_b1, s_b2, s_b3, s_b4;
- //}
- [StructLayout(LayoutKind.Sequential)]
- public struct sockaddr_in
- {
- public short sin_family;
- public ushort sin_port;
- public in_addr sin_addr;
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
- public byte[] sLibNamesin_zero;
- }
- /****************************************************/
- [StructLayout(LayoutKind.Sequential)]
- public struct WSABUF
- {
- public int Length;
- public IntPtr Buffer;
- }
- /// <summary>
- /// 名称:IP 地址条目结构体
- /// 描述:IP 地址的地址簇/地址值结构体
- /// </summary>
- public struct IPAddr
- {
- public IPAddrType Type;
- public string Address;
- public string TypeString;
- }
- /// <summary>
- /// DnsHelper
- /// </summary>
- public class DnsHelper
- {
- /// <summary>
- /// 获取本机ipv4+ipv6地址
- /// hp-socket可用的ip地址结构
- /// </summary>
- /// <returns></returns>
- public static List<IPAddr> GetLocalHostAddressesToIPAddrList()
- {
- return Dns.GetHostAddresses(Dns.GetHostName()).Where(p => p.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork ||
- p.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6).
- Select(p => new IPAddr
- {
- Type = p.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork ? IPAddrType.IPV4 : IPAddrType.IPV6,
- Address = p.ToString(),
- }).ToList();
- }
- /// <summary>
- /// 获取本机ipv4+ipv6地址
- /// .net自带的ip地址结构
- /// </summary>
- /// <returns></returns>
- public static IPAddress[] GetLocalHostAddresses()
- {
- return Dns.GetHostAddresses(Dns.GetHostName());
- }
- }
- }
- /// <summary>
- /// ANSI版本
- /// </summary>
- public class Sdk
- {
- /// <summary>
- /// HPSocket的文件路径
- /// </summary>
- public const string HPSOCKET_DLL_PATH = "hpsocket4c";
- /*****************************************************************************************************/
- /******************************************** 公共类、接口 ********************************************/
- /*****************************************************************************************************/
- /****************************************************/
- /************** HPSocket4C.dll 回调函数 **************/
- /* Agent & Server & Client */
- public delegate HandleResult OnSend(IntPtr pSender, IntPtr connId, IntPtr pData, int length);
- public delegate HandleResult OnReceive(IntPtr pSender, IntPtr connId, IntPtr pData, int length);
- public delegate HandleResult OnPullReceive(IntPtr pSender, IntPtr connId, int length);
- public delegate HandleResult OnClose(IntPtr pSender, IntPtr connId, SocketOperation enOperation, int errorCode);
- public delegate HandleResult OnHandShake(IntPtr pSender, IntPtr connId);
- /* Agent & Server */
- public delegate HandleResult OnShutdown(IntPtr pSender);
- /* Agent & Client */
- public delegate HandleResult OnPrepareConnect(IntPtr pSender, IntPtr connId /* IntPtr pClient */, IntPtr socket);
- public delegate HandleResult OnConnect(IntPtr pSender, IntPtr connId /* IntPtr pClient */);
- /* Server */
- public delegate HandleResult OnPrepareListen(IntPtr pSender, IntPtr soListen);
- public delegate HandleResult OnAccept(IntPtr pSender, IntPtr connId, IntPtr pClient);
- /****************************************************/
- /************** HPSocket4C.dll 导出函数 **************/
- /// <summary>
- /// 创建 TcpServer 对象
- /// </summary>
- /// <param name="pListener"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_TcpServer(IntPtr pListener);
- /// <summary>
- /// 创建 TcpClient 对象
- /// </summary>
- /// <param name="pListener"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_TcpClient(IntPtr pListener);
- /// <summary>
- /// 创建 TcpAgent 对象
- /// </summary>
- /// <param name="pListener"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_TcpAgent(IntPtr pListener);
- /// <summary>
- /// 创建 TcpPullServer 对象
- /// </summary>
- /// <param name="pListener"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_TcpPullServer(IntPtr pListener);
- /// <summary>
- /// 创建 TcpPullClient 对象
- /// </summary>
- /// <param name="pListener"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_TcpPullClient(IntPtr pListener);
- /// <summary>
- /// 创建 TcpPullAgent 对象
- /// </summary>
- /// <param name="pListener"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_TcpPullAgent(IntPtr pListener);
- /// <summary>
- /// 创建 HP_TcpPackServer 对象
- /// </summary>
- /// <param name="pListener"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_TcpPackServer(IntPtr pListener);
- /// <summary>
- /// 创建 HP_TcpPackAgent 对象
- /// </summary>
- /// <param name="pListener"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_TcpPackAgent(IntPtr pListener);
- /// <summary>
- /// 创建 HP_TcpPackAgent 对象
- /// </summary>
- /// <param name="pListener"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_TcpPackClient(IntPtr pListener);
- /// <summary>
- /// 创建 UdpServer 对象
- /// </summary>
- /// <param name="pListener"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_UdpServer(IntPtr pListener);
- /// <summary>
- /// 创建 UdpClient 对象
- /// </summary>
- /// <param name="pListener"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_UdpClient(IntPtr pListener);
- /// <summary>
- /// 创建 HP_UdpCast 对象
- /// </summary>
- /// <param name="pListener"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_UdpCast(IntPtr pListener);
- /// <summary>
- /// 销毁 TcpServer 对象
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_TcpServer(IntPtr pServer);
- /// <summary>
- /// 销毁 TcpClient 对象
- /// </summary>
- /// <param name="pClient"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_TcpClient(IntPtr pClient);
- /// <summary>
- /// 销毁 TcpAgent 对象
- /// </summary>
- /// <param name="pAgent"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_TcpAgent(IntPtr pAgent);
- /// <summary>
- /// 销毁 TcpPullServer 对象
- /// </summary>
- /// <param name="pClient"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_TcpPullServer(IntPtr pServer);
- /// <summary>
- /// 销毁 TcpPullClient 对象
- /// </summary>
- /// <param name="pClient"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_TcpPullClient(IntPtr pClient);
- /// <summary>
- /// 销毁 TcpPullAgent 对象
- /// </summary>
- /// <param name="pAgent"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_TcpPullAgent(IntPtr pAgent);
- /// <summary>
- /// 销毁 HP_TcpPackServer 对象
- /// </summary>
- /// <param name="pServer"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_TcpPackServer(IntPtr pServer);
- /// <summary>
- /// 销毁 HP_TcpPackAgent 对象
- /// </summary>
- /// <param name="pAgent"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_TcpPackAgent(IntPtr pAgent);
- /// <summary>
- /// 销毁 HP_TcpPackClient 对象
- /// </summary>
- /// <param name="pClient"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_TcpPackClient(IntPtr pClient);
- /// <summary>
- /// 销毁 UdpServer 对象
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_UdpServer(IntPtr pServer);
- /// <summary>
- /// 销毁 UdpClient 对象
- /// </summary>
- /// <param name="pClient"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_UdpClient(IntPtr pClient);
- /// <summary>
- /// 销毁 HP_UdpCast 对象
- /// </summary>
- /// <param name="pCast"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_UdpCast(IntPtr pCast);
- /// <summary>
- /// 创建 TcpServerListener 对象
- /// </summary>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_TcpServerListener();
- /// <summary>
- /// 创建 TcpClientListener 对象
- /// </summary>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_TcpClientListener();
- /// <summary>
- /// 创建 TcpAgentListener 对象
- /// </summary>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_TcpAgentListener();
- /// <summary>
- /// 创建 TcpPullServerListener 对象
- /// </summary>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_TcpPullServerListener();
- /// <summary>
- /// 创建 TcpPullClientListener 对象
- /// </summary>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_TcpPullClientListener();
- /// <summary>
- /// 创建 TcpPullAgentListener 对象
- /// </summary>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_TcpPullAgentListener();
- /// <summary>
- /// 创建 TcpPackServerListener 对象
- /// </summary>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_TcpPackServerListener();
- /// <summary>
- /// 创建 TcpPackClientListener 对象
- /// </summary>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_TcpPackClientListener();
- /// <summary>
- /// 创建 TcpPackAgentListener 对象
- /// </summary>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_TcpPackAgentListener();
- /// <summary>
- /// 创建 UdpServerListener 对象
- /// </summary>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_UdpServerListener();
- /// <summary>
- /// 创建 UdpClientListener 对象
- /// </summary>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_UdpClientListener();
- /// <summary>
- /// 创建 HP_UdpCastListener 对象
- /// </summary>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_UdpCastListener();
- /// <summary>
- /// 销毁 TcpServerListener 对象
- /// </summary>
- /// <param name="pListener"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_TcpServerListener(IntPtr pListener);
- /// <summary>
- /// 销毁 TcpClientListener 对象
- /// </summary>
- /// <param name="pListener"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_TcpClientListener(IntPtr pListener);
- /// <summary>
- /// 销毁 TcpAgentListener 对象
- /// </summary>
- /// <param name="pListener"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_TcpAgentListener(IntPtr pListener);
- /// <summary>
- /// 销毁 TcpPullServerListener 对象
- /// </summary>
- /// <param name="pListener"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_TcpPullServerListener(IntPtr pListener);
- /// <summary>
- /// 销毁 TcpPullClientListener 对象
- /// </summary>
- /// <param name="pListener"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_TcpPullClientListener(IntPtr pListener);
- /// <summary>
- /// 销毁 TcpPullAgentListener 对象
- /// </summary>
- /// <param name="pListener"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_TcpPullAgentListener(IntPtr pListener);
- /// <summary>
- /// 销毁 TcpPackServerListener 对象
- /// </summary>
- /// <param name="pListener"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_TcpPackServerListener(IntPtr pListener);
- /// <summary>
- /// 销毁 TcpPackClientListener 对象
- /// </summary>
- /// <param name="pListener"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_TcpPackClientListener(IntPtr pListener);
- /// <summary>
- /// 销毁 TcpPackAgentListener 对象
- /// </summary>
- /// <param name="pListener"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_TcpPackAgentListener(IntPtr pListener);
- /// <summary>
- /// 销毁 UdpServerListener 对象
- /// </summary>
- /// <param name="pListener"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_UdpServerListener(IntPtr pListener);
- /// <summary>
- /// 销毁 UdpClientListener 对象
- /// </summary>
- /// <param name="pListener"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_UdpClientListener(IntPtr pListener);
- /// <summary>
- /// 销毁 HP_UdpCastListener 对象
- /// </summary>
- /// <param name="pListener"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_UdpCastListener(IntPtr pListener);
- /**********************************************************************************/
- /***************************** Server 回调函数设置方法 *****************************/
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_Server_OnPrepareListen(IntPtr pListener, OnPrepareListen fn);
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_Server_OnAccept(IntPtr pListener, OnAccept fn);
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_Server_OnHandShake(IntPtr pListener, OnHandShake fn);
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_Server_OnSend(IntPtr pListener, OnSend fn);
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_Server_OnReceive(IntPtr pListener, OnReceive fn);
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_Server_OnPullReceive(IntPtr pListener, OnPullReceive fn);
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_Server_OnClose(IntPtr pListener, OnClose fn);
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_Server_OnShutdown(IntPtr pListener, OnShutdown fn);
- /**********************************************************************************/
- /***************************** Client 回调函数设置方法 *****************************/
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_Client_OnPrepareConnect(IntPtr pListener, OnPrepareConnect fn);
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_Client_OnConnect(IntPtr pListener, OnConnect fn);
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_Client_OnHandShake(IntPtr pListener, OnHandShake fn);
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_Client_OnSend(IntPtr pListener, OnSend fn);
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_Client_OnReceive(IntPtr pListener, OnReceive fn);
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_Client_OnPullReceive(IntPtr pListener, OnPullReceive fn);
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_Client_OnClose(IntPtr pListener, OnClose fn);
- /**********************************************************************************/
- /****************************** Agent 回调函数设置方法 *****************************/
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_Agent_OnPrepareConnect(IntPtr pListener, OnPrepareConnect fn);
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_Agent_OnConnect(IntPtr pListener, OnConnect fn);
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_Agent_OnHandShake(IntPtr pListener, OnHandShake fn);
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_Agent_OnSend(IntPtr pListener, OnSend fn);
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_Agent_OnReceive(IntPtr pListener, OnReceive fn);
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_Agent_OnPullReceive(IntPtr pListener, OnPullReceive fn);
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_Agent_OnClose(IntPtr pListener, OnClose fn);
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Set_FN_Agent_OnShutdown(IntPtr pListener, OnShutdown fn);
- /**************************************************************************/
- /***************************** Server 操作方法 *****************************/
- /// <summary>
- /// 名称:启动通信组件
- /// 描述:启动服务端通信组件,启动完成后可开始接收客户端连接并收发数据
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="pszBindAddress">监听地址</param>
- /// <param name="usPort">监听端口</param>
- /// <returns>失败,可通过 GetLastError() 获取错误代码</returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Server_Start(IntPtr pServer, string pszBindAddress, ushort usPort);
- /// <summary>
- /// 关闭服务端通信组件,关闭完成后断开所有客户端连接并释放所有资源
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns>失败,可通过 GetLastError() 获取错误代码</returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Server_Stop(IntPtr pServer);
- /// <summary>
- /// 用户通过该方法向指定客户端发送数据
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="connId">连接 ID</param>
- /// <param name="pBuffer">发送数据长度</param>
- /// <param name="length">发送数据长度</param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Server_Send(IntPtr pServer, IntPtr connId, byte[] pBuffer, int length);
- /// <summary>
- /// 用户通过该方法向指定客户端发送数据
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="connId">连接 ID</param>
- /// <param name="pBuffer">发送数据长度</param>
- /// <param name="length">发送数据长度</param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Server_Send(IntPtr pServer, IntPtr connId, IntPtr pBuffer, int length);
- /// <summary>
- /// 用户通过该方法向指定客户端发送数据
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="connId"></param>
- /// <param name="pBuffer"></param>
- /// <param name="length"></param>
- /// <param name="iOffset">针对pBuffer的偏移</param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Server_SendPart(IntPtr pServer, IntPtr connId, byte[] pBuffer, int length, int iOffset);
- /// <summary>
- /// 用户通过该方法向指定客户端发送数据
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="connId"></param>
- /// <param name="pBuffer"></param>
- /// <param name="length"></param>
- /// <param name="iOffset">针对pBuffer的偏移</param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Server_SendPart(IntPtr pServer, IntPtr connId, IntPtr pBuffer, int length, int iOffset);
- /// <summary>
- /// 发送多组数据
- /// 向指定连接发送多组数据
- /// TCP - 顺序发送所有数据包
- /// UDP - 把所有数据包组合成一个数据包发送(数据包的总长度不能大于设置的 UDP 包最大长度)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="connId">连接 ID</param>
- /// <param name="pBuffers">发送缓冲区数组</param>
- /// <param name="iCount">发送缓冲区数目</param>
- /// <returns>TRUE.成功,FALSE.失败,可通过 Windows API 函数 ::GetLastError() 获取 Windows 错误代码</returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Server_SendPackets(IntPtr pServer, IntPtr connId, WSABUF[] pBuffers, int iCount);
- /// <summary>
- /// 名称:暂停/恢复接收
- /// 描述:暂停/恢复某个连接的数据接收工作
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwConnID">连接 ID</param>
- /// <param name="bPause">TRUE - 暂停, FALSE - 恢复</param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Server_PauseReceive(IntPtr pServer, IntPtr dwConnID, bool bPause);
- /// <summary>
- /// 断开与某个客户端的连接
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="connId">连接 ID</param>
- /// <param name="bForce">是否强制断开连接</param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Server_Disconnect(IntPtr pServer, IntPtr connId, bool bForce);
- /// <summary>
- /// 断开超过指定时长的连接
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwPeriod">时长(毫秒)</param>
- /// <param name="bForce">是否强制断开连接</param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Server_DisconnectLongConnections(IntPtr pServer, uint dwPeriod, bool bForce);
- /// <summary>
- /// 断开超过指定时长的静默连接
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwPeriod">时长(毫秒)</param>
- /// <param name="bForce">是否强制断开连接</param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Server_DisconnectSilenceConnections(IntPtr pServer, uint dwPeriod, bool bForce);
- /******************************************************************************/
- /***************************** Server 属性访问方法 *****************************/
- /// <summary>
- /// 设置数据发送策略
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="enSendPolicy"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Server_SetSendPolicy(IntPtr pServer, SendPolicy enSendPolicy);
- /// <summary>
- /// 获取数据发送策略
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern SendPolicy HP_Server_GetSendPolicy(IntPtr pServer);
- /// <summary>
- /// 设置连接的附加数据
- /// 是否为连接绑定附加数据或者绑定什么样的数据,均由应用程序只身决定
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="connId">连接 ID</param>
- /// <param name="pExtra"></param>
- /// <returns>若返回 false 失败则为(无效的连接 ID)</returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Server_SetConnectionExtra(IntPtr pServer, IntPtr connId, IntPtr pExtra);
- /// <summary>
- /// 获取连接的附加数据
- /// 是否为连接绑定附加数据或者绑定什么样的数据,均由应用程序只身决定
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="connId">连接 ID</param>
- /// <param name="pExtra">数据指针</param>
- /// <returns>若返回 false 失败则为(无效的连接 ID)</returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Server_GetConnectionExtra(IntPtr pServer, IntPtr connId, ref IntPtr pExtra);
- /// <summary>
- /// 检测是否为安全连接(SSL/HTTPS)
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Server_IsSecure(IntPtr pServer);
- /// <summary>
- /// 检查通信组件是否已启动
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Server_HasStarted(IntPtr pServer);
- /// <summary>
- /// 查看通信组件当前状态
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern ServiceState HP_Server_GetState(IntPtr pServer);
- /// <summary>
- /// 获取最近一次失败操作的错误代码
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern SocketError HP_Server_GetLastError(IntPtr pServer);
- /// <summary>
- /// 获取最近一次失败操作的错误描述
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr HP_Server_GetLastErrorDesc(IntPtr pServer);
- /// <summary>
- /// 获取连接中未发出数据的长度
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="connId"></param>
- /// <param name="piPending"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Server_GetPendingDataLength(IntPtr pServer, IntPtr connId, ref int piPending);
- /// <summary>
- /// 获取连接的数据接收状态
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwConnID"></param>
- /// <param name="pbPaused"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Server_IsPauseReceive(IntPtr pServer, IntPtr dwConnID, ref int pbPaused);
- /// <summary>
- /// 检测是否有效连接
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwConnID"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Server_IsConnected(IntPtr pServer, IntPtr dwConnID);
- /// <summary>
- /// 获取客户端连接数
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_Server_GetConnectionCount(IntPtr pServer);
- /// <summary>
- /// 获取所有连接的 CONNID
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="pIDs"></param>
- /// <param name="pdwCount"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Server_GetAllConnectionIDs(IntPtr pServer, IntPtr[] pIDs, ref uint pdwCount);
- /// <summary>
- /// 获取某个客户端连接时长(毫秒)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="connId"></param>
- /// <param name="pdwPeriod"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Server_GetConnectPeriod(IntPtr pServer, IntPtr connId, ref uint pdwPeriod);
- /// <summary>
- /// 获取某个连接静默时间(毫秒)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="connId"></param>
- /// <param name="pdwPeriod"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Server_GetSilencePeriod(IntPtr pServer, IntPtr connId, ref uint pdwPeriod);
- /// <summary>
- /// 获取监听 Socket 的地址信息
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="lpszAddress"></param>
- /// <param name="piAddressLen"></param>
- /// <param name="pusPort"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Server_GetListenAddress(IntPtr pServer, [MarshalAs(UnmanagedType.LPStr)] StringBuilder lpszAddress, ref int piAddressLen, ref ushort pusPort);
- /// <summary>
- /// 获取某个连接的本地地址信息
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="connId"></param>
- /// <param name="lpszAddress"></param>
- /// <param name="piAddressLen">传入传出值,大小最好在222.222.222.222的长度以上</param>
- /// <param name="pusPort"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Server_GetLocalAddress(IntPtr pServer, IntPtr connId, [MarshalAs(UnmanagedType.LPStr)] StringBuilder lpszAddress, ref int piAddressLen, ref ushort pusPort);
- /// <summary>
- /// 获取某个连接的远程地址信息
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="connId"></param>
- /// <param name="lpszAddress"></param>
- /// <param name="piAddressLen">传入传出值,大小最好在222.222.222.222的长度以上</param>
- /// <param name="pusPort"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Server_GetRemoteAddress(IntPtr pServer, IntPtr connId, [MarshalAs(UnmanagedType.LPStr)] StringBuilder lpszAddress, ref int piAddressLen, ref ushort pusPort);
- /// <summary>
- /// 设置 OnSend 事件同步策略(默认:OSSP_NONE,不同步)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="syncPolicy"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Server_SetOnSendSyncPolicy(IntPtr pServer, OnSendSyncPolicy syncPolicy);
- /// <summary>
- /// 获取 OnSend 事件同步策略
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern OnSendSyncPolicy HP_Server_GetOnSendSyncPolicy(IntPtr pServer);
- /// <summary>
- /// 设置 Socket 缓存对象锁定时间(毫秒,在锁定期间该 Socket 缓存对象不能被获取使用)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwFreeSocketObjLockTime"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Server_SetFreeSocketObjLockTime(IntPtr pServer, uint dwFreeSocketObjLockTime);
- /// <summary>
- /// 设置 Socket 缓存池大小(通常设置为平均并发连接数量的 1/3 - 1/2)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwFreeSocketObjPool"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Server_SetFreeSocketObjPool(IntPtr pServer, uint dwFreeSocketObjPool);
- /// <summary>
- /// 设置内存块缓存池大小(通常设置为 Socket 缓存池大小的 2 - 3 倍)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwFreeBufferObjPool"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Server_SetFreeBufferObjPool(IntPtr pServer, uint dwFreeBufferObjPool);
- /// <summary>
- /// 设置 Socket 缓存池回收阀值(通常设置为 Socket 缓存池大小的 3 倍)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwFreeSocketObjHold"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Server_SetFreeSocketObjHold(IntPtr pServer, uint dwFreeSocketObjHold);
- /// <summary>
- /// 设置内存块缓存池回收阀值(通常设置为内存块缓存池大小的 3 倍)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwFreeBufferObjHold"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Server_SetFreeBufferObjHold(IntPtr pServer, uint dwFreeBufferObjHold);
- /// <summary>
- /// 设置最大连接数(组件会根据设置值预分配内存,因此需要根据实际情况设置,不宜过大)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwMaxConnectionCount"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Server_SetMaxConnectionCount(IntPtr pServer, uint dwWMaxConnectionCount);
- /// <summary>
- /// 设置工作线程数量(通常设置为 2 * CPU + 2)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwWorkerThreadCount"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Server_SetWorkerThreadCount(IntPtr pServer, uint dwWorkerThreadCount);
- /// <summary>
- /// 设置是否标记静默时间(设置为 TRUE 时 DisconnectSilenceConnections() 和 GetSilencePeriod() 才有效,默认:FALSE)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="bMarkSilence"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Server_SetMarkSilence(IntPtr pServer, bool bMarkSilence);
- /// <summary>
- /// 获取 Socket 缓存对象锁定时间
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_Server_GetFreeSocketObjLockTime(IntPtr pServer);
- /// <summary>
- /// 获取 Socket 缓存池大小
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_Server_GetFreeSocketObjPool(IntPtr pServer);
- /// <summary>
- /// 获取内存块缓存池大小
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_Server_GetFreeBufferObjPool(IntPtr pServer);
- /// <summary>
- /// 获取 Socket 缓存池回收阀值
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_Server_GetFreeSocketObjHold(IntPtr pServer);
- /// <summary>
- /// 获取内存块缓存池回收阀值
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_Server_GetFreeBufferObjHold(IntPtr pServer);
- /// <summary>
- /// 获取最大连接数
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_Server_GetMaxConnectionCount(IntPtr pServer);
- /// <summary>
- /// 获取工作线程数量
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_Server_GetWorkerThreadCount(IntPtr pServer);
- /// <summary>
- /// 检测是否标记静默时间
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Server_IsMarkSilence(IntPtr pServer);
- /**********************************************************************************/
- /***************************** TCP Server 操作方法 *****************************/
- /// <summary>
- /// 名称:发送小文件
- /// 描述:向指定连接发送 4096 KB 以下的小文件
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="connId">连接 ID</param>
- /// <param name="lpszFileName">文件路径</param>
- /// <param name="pHead">头部附加数据</param>
- /// <param name="pTail">尾部附加数据</param>
- /// <returns>TRUE.成功 FALSE -- 失败,可通过 Windows API 函数 ::GetLastError() 获取 Windows 错误代码</returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_TcpServer_SendSmallFile(IntPtr pServer, IntPtr connId, string lpszFileName, ref WSABUF pHead, ref WSABUF pTail);
- /**********************************************************************************/
- /***************************** TCP Server 属性访问方法 *****************************/
- /// <summary>
- /// 设置 Accept 预投递数量(根据负载调整设置,Accept 预投递数量越大则支持的并发连接请求越多)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwAcceptSocketCount"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_TcpServer_SetAcceptSocketCount(IntPtr pServer, uint dwAcceptSocketCount);
- /// <summary>
- /// 设置通信数据缓冲区大小(根据平均通信数据包大小调整设置,通常设置为 1024 的倍数)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwSocketBufferSize"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_TcpServer_SetSocketBufferSize(IntPtr pServer, uint dwSocketBufferSize);
- /// <summary>
- /// 设置监听 Socket 的等候队列大小(根据并发连接数量调整设置)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwSocketListenQueue"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_TcpServer_SetSocketListenQueue(IntPtr pServer, uint dwSocketListenQueue);
- /// <summary>
- /// 设置心跳包间隔(毫秒,0 则不发送心跳包)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwKeepAliveTime"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_TcpServer_SetKeepAliveTime(IntPtr pServer, uint dwKeepAliveTime);
- /// <summary>
- /// 设置心跳确认包检测间隔(毫秒,0 不发送心跳包,如果超过若干次 [默认:WinXP 5 次, Win7 10 次] 检测不到心跳确认包则认为已断线)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwKeepAliveInterval"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_TcpServer_SetKeepAliveInterval(IntPtr pServer, uint dwKeepAliveInterval);
- /// <summary>
- /// 获取 Accept 预投递数量
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_TcpServer_GetAcceptSocketCount(IntPtr pServer);
- /// <summary>
- /// 获取通信数据缓冲区大小
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_TcpServer_GetSocketBufferSize(IntPtr pServer);
- /// <summary>
- /// 获取监听 Socket 的等候队列大小
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_TcpServer_GetSocketListenQueue(IntPtr pServer);
- /// <summary>
- /// 获取心跳检查次数
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_TcpServer_GetKeepAliveTime(IntPtr pServer);
- /// <summary>
- /// 获取心跳检查间隔
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_TcpServer_GetKeepAliveInterval(IntPtr pServer);
- /**********************************************************************************/
- /***************************** UDP Server 属性访问方法 *****************************/
- /// <summary>
- /// 设置数据报文最大长度(建议在局域网环境下不超过 1472 字节,在广域网环境下不超过 548 字节)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwMaxDatagramSize"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpServer_SetMaxDatagramSize(IntPtr pServer, uint dwMaxDatagramSize);
- /// <summary>
- /// 获取数据报文最大长度
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_UdpServer_GetMaxDatagramSize(IntPtr pServer);
- /// <summary>
- /// 设置 Receive 预投递数量(根据负载调整设置,Receive 预投递数量越大则丢包概率越小)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwPostReceiveCount"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpServer_SetPostReceiveCount(IntPtr pServer, uint dwPostReceiveCount);
- /// <summary>
- /// 获取 Receive 预投递数量
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_UdpServer_GetPostReceiveCount(IntPtr pServer);
- /// <summary>
- /// 设置监测包尝试次数(0 则不发送监测跳包,如果超过最大尝试次数则认为已断线)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwMaxDatagramSize"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpServer_SetDetectAttempts(IntPtr pServer, uint dwMaxDatagramSize);
- /// <summary>
- /// 设置监测包发送间隔(秒,0 不发送监测包)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwMaxDatagramSize"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpServer_SetDetectInterval(IntPtr pServer, uint dwMaxDatagramSize);
- /// <summary>
- /// 获取心跳检查次数
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_UdpServer_GetDetectAttempts(IntPtr pServer);
- /// <summary>
- /// 获取心跳检查间隔
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_UdpServer_GetDetectInterval(IntPtr pServer);
- /******************************************************************************/
- /***************************** Client 组件操作方法 *****************************/
- /// <summary>
- /// 启动客户端通信组件并连接服务端,启动完成后可开始收发数据
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="pszRemoteAddress">服务端地址</param>
- /// <param name="usPort">服务端端口</param>
- /// <param name="bAsyncConnect">是否采用异步 Connect</param>
- /// <returns>失败,可通过 HP_Client_GetLastError() 获取错误代码</returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Client_Start(IntPtr pClient, string pszRemoteAddress, ushort usPort, bool bAsyncConnect);
- /// <summary>
- /// 启动通信组件(并指定绑定地址), 启动客户端通信组件并连接服务端,启动完成后可开始收发数据
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="lpszRemoteAddress">服务端地址</param>
- /// <param name="usPort">服务端端口</param>
- /// <param name="bAsyncConnect">是否采用异步 Connect</param>
- /// <param name="lpszBindAddress">绑定地址(默认:nullptr,TcpClient/UdpClient -> 不执行绑定操作,UdpCast 绑定 -> 0.0.0.0)</param>
- /// <returns>失败,可通过 HP_Client_GetLastError() 获取错误代码</returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Client_StartWithBindAddress(IntPtr pClient, string lpszRemoteAddress, ushort usPort, bool bAsyncConnect, string lpszBindAddress);
- /// <summary>
- /// 名称:启动通信组件(并指定绑定地址)
- /// 描述:启动客户端通信组件并连接服务端,启动完成后可开始收发数据
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="lpszRemoteAddress">服务端地址</param>
- /// <param name="usPort">服务端端口</param>
- /// <param name="bAsyncConnect">是否采用异步 Connect</param>
- /// <param name="lpszBindAddress">绑定地址(默认:nullptr,TcpClient/UdpClient -> 不执行绑定操作,UdpCast 绑定 -> 0.0.0.0)</param>
- /// <param name="usLocalPort">本地端口(默认:0)</param>
- /// <returns>失败,可通过 HP_Client_GetLastError() 获取错误代码</returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Client_StartWithBindAddressAndLocalPort(IntPtr pClient, string lpszRemoteAddress, ushort usPort, bool bAsyncConnect, string lpszBindAddress, ushort usLocalPort);
- /// <summary>
- /// 关闭客户端通信组件,关闭完成后断开与服务端的连接并释放所有资源
- /// </summary>
- /// <param name="pClient"></param>
- /// <returns>失败,可通过 HP_Client_GetLastError() 获取错误代码</returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Client_Stop(IntPtr pClient);
- /// <summary>
- /// 用户通过该方法向服务端发送数据
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="connId">连接 ID(保留参数,目前该参数并未使用)</param>
- /// <param name="pBuffer">发送数据缓冲区</param>
- /// <param name="length">发送数据长度</param>
- /// <returns>失败,可通过 HP_Client_GetLastError() 获取错误代码</returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Client_Send(IntPtr pClient, byte[] pBuffer, int length);
- /// <summary>
- /// 用户通过该方法向服务端发送数据
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="connId">连接 ID(保留参数,目前该参数并未使用)</param>
- /// <param name="pBuffer">发送数据缓冲区</param>
- /// <param name="length">发送数据长度</param>
- /// <returns>失败,可通过 HP_Client_GetLastError() 获取错误代码</returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Client_Send(IntPtr pClient, IntPtr pBuffer, int length);
- /// <summary>
- /// 用户通过该方法向服务端发送数据
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="pBuffer"></param>
- /// <param name="length"></param>
- /// <param name="iOffset">针对pBuffer的偏移</param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Client_SendPart(IntPtr pClient, byte[] pBuffer, int length, int iOffset);
- /// <summary>
- /// 用户通过该方法向服务端发送数据
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="pBuffer"></param>
- /// <param name="length"></param>
- /// <param name="iOffset">针对pBuffer的偏移</param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Client_SendPart(IntPtr pClient, IntPtr pBuffer, int length, int iOffset);
- /// <summary>
- /// 发送多组数据
- /// 向服务端发送多组数据
- /// TCP - 顺序发送所有数据包
- /// UDP - 把所有数据包组合成一个数据包发送(数据包的总长度不能大于设置的 UDP 包最大长度)
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="pBuffers">发送缓冲区数组</param>
- /// <param name="iCount">发送缓冲区数目</param>
- /// <returns>TRUE.成功,FALSE.失败,可通过 Windows API 函数 ::GetLastError() 获取 Windows 错误代码</returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Client_SendPackets(IntPtr pClient, WSABUF[] pBuffers, int iCount);
- /// <summary>
- /// 名称:暂停/恢复接收
- /// 描述:暂停/恢复某个连接的数据接收工作
- /// </summary>
- /// <param name="pClient">TRUE - 暂停, FALSE - 恢复</param>
- /// <param name="bPause">TRUE - 暂停, FALSE - 恢复</param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Client_PauseReceive(IntPtr pClient, int bPause);
- /******************************************************************************/
- /***************************** Client 属性访问方法 *****************************/
- /// <summary>
- /// 设置连接的附加数据
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="pExtra"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Client_SetExtra(IntPtr pClient, IntPtr pExtra);
- /// <summary>
- /// 获取连接的附加数据
- /// </summary>
- /// <param name="pClient"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr HP_Client_GetExtra(IntPtr pClient);
- /// <summary>
- /// 检测是否为安全连接(SSL/HTTPS)
- /// </summary>
- /// <param name="pClient"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Client_IsSecure(IntPtr pClient);
- /// <summary>
- /// 检查通信组件是否已启动
- /// </summary>
- /// <param name="pClient"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Client_HasStarted(IntPtr pClient);
- /// <summary>
- /// 查看通信组件当前状态
- /// </summary>
- /// <param name="pClient"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern ServiceState HP_Client_GetState(IntPtr pClient);
- /// <summary>
- /// 获取最近一次失败操作的错误代码
- /// </summary>
- /// <param name="pClient"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern SocketError HP_Client_GetLastError(IntPtr pClient);
- /// <summary>
- /// 获取最近一次失败操作的错误描述
- /// </summary>
- /// <param name="pClient"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr HP_Client_GetLastErrorDesc(IntPtr pClient);
- /// <summary>
- /// 获取该组件对象的连接 ID
- /// </summary>
- /// <param name="pClient"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr HP_Client_GetConnectionID(IntPtr pClient);
- /// <summary>
- /// 获取 Client Socket 的地址信息
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="lpszAddress"></param>
- /// <param name="piAddressLen"></param>
- /// <param name="pusPort"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Client_GetLocalAddress(IntPtr pClient, [MarshalAs(UnmanagedType.LPStr)] StringBuilder lpszAddress, ref int piAddressLen, ref ushort pusPort);
- /// <summary>
- /// 获取连接的远程主机信息
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="lpszHost"></param>
- /// <param name="piHostLen"></param>
- /// <param name="pusPort"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Client_GetRemoteHost(IntPtr pClient, [MarshalAs(UnmanagedType.LPStr)] StringBuilder lpszHost, ref int piHostLen, ref ushort pusPort);
- /// <summary>
- /// 获取连接中未发出数据的长度
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="piPending"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Client_GetPendingDataLength(IntPtr pClient, ref int piPending);
- /// <summary>
- /// 获取连接的数据接收状态
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="pbPaused"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Client_IsPauseReceive(IntPtr pClient, ref int pbPaused);
- /// <summary>
- /// 检测是否有效连接
- /// </summary>
- /// <param name="pClient"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Client_IsConnected(IntPtr pClient);
- /// <summary>
- /// 设置内存块缓存池大小(通常设置为 -> PUSH 模型:5 - 10;PULL 模型:10 - 20 )
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="dwFreeBufferPoolSize"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Client_SetFreeBufferPoolSize(IntPtr pClient, uint dwFreeBufferPoolSize);
- /// <summary>
- /// 设置内存块缓存池回收阀值(通常设置为内存块缓存池大小的 3 倍)
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="dwFreeBufferPoolHold"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Client_SetFreeBufferPoolHold(IntPtr pClient, uint dwFreeBufferPoolHold);
- /// <summary>
- /// 获取内存块缓存池大小
- /// </summary>
- /// <param name="pClient"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_Client_GetFreeBufferPoolSize(IntPtr pClient);
- /// <summary>
- /// 获取内存块缓存池回收阀值
- /// </summary>
- /// <param name="pClient"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_Client_GetFreeBufferPoolHold(IntPtr pClient);
- /**********************************************************************************/
- /***************************** TCP Client 操作方法 *****************************/
- /// <summary>
- /// 名称:发送小文件
- /// 描述:向指定连接发送 4096 KB 以下的小文件
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="lpszFileName">文件路径</param>
- /// <param name="pHead">头部附加数据</param>
- /// <param name="pTail">尾部附加数据</param>
- /// <returns>TRUE.成功 FALSE -- 失败,可通过 Windows API 函数 ::GetLastError() 获取 Windows 错误代码</returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_TcpClient_SendSmallFile(IntPtr pClient, string lpszFileName, ref WSABUF pHead, ref WSABUF pTail);
- /**********************************************************************************/
- /***************************** TCP Client 属性访问方法 *****************************/
- /// <summary>
- /// 设置通信数据缓冲区大小(根据平均通信数据包大小调整设置,通常设置为:(N * 1024) - sizeof(TBufferObj))
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="dwSocketBufferSize"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_TcpClient_SetSocketBufferSize(IntPtr pClient, uint dwSocketBufferSize);
- /// <summary>
- /// 设置心跳包间隔(毫秒,0 则不发送心跳包)
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="dwKeepAliveTime"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_TcpClient_SetKeepAliveTime(IntPtr pClient, uint dwKeepAliveTime);
- /// <summary>
- /// 设置心跳确认包检测间隔(毫秒,0 不发送心跳包,如果超过若干次 [默认:WinXP 5 次, Win7 10 次] 检测不到心跳确认包则认为已断线)
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="dwKeepAliveInterval"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_TcpClient_SetKeepAliveInterval(IntPtr pClient, uint dwKeepAliveInterval);
- /// <summary>
- /// 获取通信数据缓冲区大小
- /// </summary>
- /// <param name="pClient"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_TcpClient_GetSocketBufferSize(IntPtr pClient);
- /// <summary>
- /// 获取心跳检查次数
- /// </summary>
- /// <param name="pClient"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_TcpClient_GetKeepAliveTime(IntPtr pClient);
- /// <summary>
- /// 获取心跳检查间隔
- /// </summary>
- /// <param name="pClient"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_TcpClient_GetKeepAliveInterval(IntPtr pClient);
- /**********************************************************************************/
- /***************************** UDP Client 属性访问方法 *****************************/
- /// <summary>
- /// 设置数据报文最大长度(建议在局域网环境下不超过 1472 字节,在广域网环境下不超过 548 字节)
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="dwMaxDatagramSize"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpClient_SetMaxDatagramSize(IntPtr pClient, uint dwMaxDatagramSize);
- /// <summary>
- /// 获取数据报文最大长度
- /// </summary>
- /// <param name="pClient"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_UdpClient_GetMaxDatagramSize(IntPtr pClient);
- /// <summary>
- /// 设置监测包尝试次数(0 则不发送监测跳包,如果超过最大尝试次数则认为已断线
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="dwDetectAttempts"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpClient_SetDetectAttempts(IntPtr pClient, uint dwDetectAttempts);
- /// <summary>
- /// 设置监测包发送间隔(秒,0 不发送监测包)
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="dwDetectInterval"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpClient_SetDetectInterval(IntPtr pClient, uint dwDetectInterval);
- /// <summary>
- /// 获取心跳检查次数
- /// </summary>
- /// <param name="pClient"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_UdpClient_GetDetectAttempts(IntPtr pClient);
- /// <summary>
- /// 获取心跳检查间隔
- /// </summary>
- /// <param name="pClient"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_UdpClient_GetDetectInterval(IntPtr pClient);
- /**********************************************************************************/
- /****************************** UDP Cast 属性访问方法 ******************************/
- /// <summary>
- /// 设置数据报文最大长度(建议在局域网环境下不超过 1472 字节,在广域网环境下不超过 548 字节
- /// </summary>
- /// <param name="pCast"></param>
- /// <param name="dwMaxDatagramSize"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpCast_SetMaxDatagramSize(IntPtr pCast, uint dwMaxDatagramSize);
- /// <summary>
- /// 获取数据报文最大长度
- /// </summary>
- /// <param name="pCast"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_UdpCast_GetMaxDatagramSize(IntPtr pCast);
- /// <summary>
- /// 获取当前数据报的远程地址信息(通常在 OnReceive 事件中调用)
- /// </summary>
- /// <param name="pCast"></param>
- /// <param name="lpszAddress"></param>
- /// <param name="piAddressLen"></param>
- /// <param name="pusPort"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_UdpCast_GetRemoteAddress(IntPtr pCast, [MarshalAs(UnmanagedType.LPStr)] StringBuilder lpszAddress, ref int piAddressLen, ref ushort pusPort);
- /// <summary>
- /// 设置是否启用地址重用机制(默认:不启用)
- /// </summary>
- /// <param name="pCast"></param>
- /// <param name="bReuseAddress"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpCast_SetReuseAddress(IntPtr pCast, bool bReuseAddress);
- /// <summary>
- /// 检测是否启用地址重用机制
- /// </summary>
- /// <param name="pCast"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_UdpCast_IsReuseAddress(IntPtr pCast);
- /// <summary>
- /// 设置传播模式(组播或广播)
- /// </summary>
- /// <param name="pCast"></param>
- /// <param name="enCastMode"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpCast_SetCastMode(IntPtr pCast, CastMode enCastMode);
- /// <summary>
- /// 获取传播模式
- /// </summary>
- /// <param name="pCast"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern CastMode HP_UdpCast_GetCastMode(IntPtr pCast);
- /// <summary>
- /// 设置组播报文的 TTL(0 - 255)
- /// </summary>
- /// <param name="pCast"></param>
- /// <param name="iMCTtl"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpCast_SetMultiCastTtl(IntPtr pCast, int iMCTtl);
- /// <summary>
- /// 获取组播报文的 TTL
- /// </summary>
- /// <param name="pCast"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern int HP_UdpCast_GetMultiCastTtl(IntPtr pCast);
- /// <summary>
- /// 设置是否启用组播环路(TRUE or FALSE)
- /// </summary>
- /// <param name="pCast"></param>
- /// <param name="bMCLoop"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpCast_SetMultiCastLoop(IntPtr pCast, bool bMCLoop);
- /// <summary>
- /// 检测是否启用组播环路
- /// </summary>
- /// <param name="pCast"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_UdpCast_IsMultiCastLoop(IntPtr pCast);
- /**************************************************************************/
- /***************************** Agent 操作方法 *****************************/
- /// <summary>
- /// 启动通信组件
- /// 启动通信代理组件,启动完成后可开始连接远程服务器
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="pszBindAddress">监听地址</param>
- /// <param name="bAsyncConnect">是否采用异步 Connect</param>
- /// <returns>失败,可通过 GetLastError() 获取错误代码</returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Agent_Start(IntPtr pAgent, string pszBindAddress, bool bAsyncConnect);
- /// <summary>
- /// 关闭通信组件
- /// 关闭通信组件,关闭完成后断开所有连接并释放所有资源
- /// </summary>
- /// <param name="pAgent"></param>
- /// <returns>-- 失败,可通过 GetLastError() 获取错误代码</returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Agent_Stop(IntPtr pAgent);
- /// <summary>
- /// 连接服务器
- /// 连接服务器,连接成功后 IAgentListener 会接收到 OnConnect() 事件
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="pszBindAddress">服务端地址</param>
- /// <param name="usPort">服务端端口</param>
- /// <param name="pconnId">传出连接 ID</param>
- /// <returns>失败,可通过 SYS_GetLastError() 获取 Windows 错误代码</returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Agent_Connect(IntPtr pAgent, string pszBindAddress, ushort usPort, ref IntPtr pconnId);
- /// <summary>
- /// 名称:连接服务器
- /// 描述:连接服务器,连接成功后 IAgentListener 会接收到 OnConnect() / OnHandShake() 事件
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="lpszRemoteAddress">服务端地址</param>
- /// <param name="usPort">服务端端口</param>
- /// <param name="pdwConnID">传出连接</param>
- /// <param name="pExtra">连接附加数据(默认:nullptr)</param>
- /// <returns>失败,可通过函数 SYS_GetLastError() 获取 Windows 错误代码</returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Agent_ConnectWithExtra(IntPtr pAgent, string lpszRemoteAddress, ushort usPort, ref IntPtr pdwConnID, IntPtr pExtra);
- /// <summary>
- /// 名称:连接服务器
- /// 描述:连接服务器,连接成功后 IAgentListener 会接收到 OnConnect() / OnHandShake() 事件
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="lpszRemoteAddress">服务端地址</param>
- /// <param name="usPort">服务端端口</param>
- /// <param name="pdwConnID">连接 ID(默认:nullptr,不获取连接 ID)</param>
- /// <param name="usLocalPort">本地端口(默认:0)</param>
- /// <returns>失败,可通过函数 SYS_GetLastError() 获取 Windows 错误代码</returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Agent_ConnectWithLocalPort(IntPtr pAgent, string lpszRemoteAddress, ushort usPort, ref IntPtr pdwConnID, ushort usLocalPort);
- /// <summary>
- /// 名称:连接服务器
- /// 描述:连接服务器,连接成功后 IAgentListener 会接收到 OnConnect() / OnHandShake() 事件
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="lpszRemoteAddress">服务端地址</param>
- /// <param name="usPort">服务端端口</param>
- /// <param name="pdwConnID">连接 ID(默认:nullptr,不获取连接 ID)</param>
- /// <param name="lpszLocalAddress">本地地址(默认:nullptr,使用 Start() 方法中绑定的地址)</param>
- /// <returns>失败,可通过函数 SYS_GetLastError() 获取 Windows 错误代码</returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Agent_ConnectWithLocalAddress(IntPtr pAgent, string lpszRemoteAddress, ushort usPort, ref IntPtr pdwConnID, string lpszLocalAddress);
- /// <summary>
- /// 名称:连接服务器
- /// 描述:连接服务器,连接成功后 IAgentListener 会接收到 OnConnect() / OnHandShake() 事件
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="lpszRemoteAddress">服务端地址</param>
- /// <param name="usPort">服务端端口</param>
- /// <param name="pdwConnID">连接 ID(默认:nullptr,不获取连接 ID)</param>
- /// <param name="pExtra">连接附加数据(默认:nullptr)</param>
- /// <param name="usLocalPort">本地端口(默认:0)</param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Agent_ConnectWithExtraAndLocalPort(IntPtr pAgent, string lpszRemoteAddress, ushort usPort, ref IntPtr pdwConnID, IntPtr pExtra, ushort usLocalPort);
- /// <summary>
- /// 名称:连接服务器
- /// 描述:连接服务器,连接成功后 IAgentListener 会接收到 OnConnect() / OnHandShake() 事件
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="lpszRemoteAddress">服务端地址</param>
- /// <param name="usPort">服务端端口</param>
- /// <param name="pdwConnID">连接 ID(默认:nullptr,不获取连接 ID)</param>
- /// <param name="pExtra">连接附加数据(默认:nullptr)</param>
- /// <param name="usLocalPort">本地端口(默认:0)</param>
- /// <param name="lpszLocalAddress">本地地址(默认:nullptr,使用 Start() 方法中绑定的地址)</param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Agent_ConnectWithExtraAndLocalAddressPort(IntPtr pAgent, string lpszRemoteAddress, ushort usPort, ref IntPtr pdwConnID, IntPtr pExtra, ushort usLocalPort, string lpszLocalAddress);
- /// <summary>
- /// 发送数据
- /// 用户通过该方法向指定连接发送数据
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="connId">连接 ID</param>
- /// <param name="pBuffer">发送数据缓冲区</param>
- /// <param name="length">发送数据长度</param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Agent_Send(IntPtr pAgent, IntPtr connId, byte[] pBuffer, int length);
- /// <summary>
- /// 发送数据
- /// 用户通过该方法向指定连接发送数据
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="connId">连接 ID</param>
- /// <param name="pBuffer">发送数据缓冲区</param>
- /// <param name="length">发送数据长度</param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Agent_Send(IntPtr pAgent, IntPtr connId, IntPtr pBuffer, int length);
- /// <summary>
- /// 发送数据
- /// 用户通过该方法向指定连接发送数据
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="connId"></param>
- /// <param name="pBuffer"></param>
- /// <param name="length"></param>
- /// <param name="iOffset">针对pBuffer的偏移</param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Agent_SendPart(IntPtr pAgent, IntPtr connId, byte[] pBuffer, int length, int iOffset);
- /// <summary>
- /// 发送数据
- /// 用户通过该方法向指定连接发送数据
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="connId"></param>
- /// <param name="pBuffer"></param>
- /// <param name="length"></param>
- /// <param name="iOffset">针对pBuffer的偏移</param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Agent_SendPart(IntPtr pAgent, IntPtr connId, IntPtr pBuffer, int length, int iOffset);
- /// <summary>
- /// 发送多组数据
- /// 向指定连接发送多组数据
- /// TCP - 顺序发送所有数据包
- /// UDP - 把所有数据包组合成一个数据包发送(数据包的总长度不能大于设置的 UDP 包最大长度)
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="connId">连接 ID</param>
- /// <param name="pBuffers">发送缓冲区数组</param>
- /// <param name="iCount">发送缓冲区数目</param>
- /// <returns>TRUE.成功,FALSE .失败,可通过 Windows API 函数 ::GetLastError() 获取 Windows 错误代码</returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Agent_SendPackets(IntPtr pAgent, IntPtr connId, WSABUF[] pBuffers, int iCount);
- /// <summary>
- /// 名称:暂停/恢复接收
- /// 描述:暂停/恢复某个连接的数据接收工作
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="dwConnID"></param>
- /// <param name="bPause">TRUE - 暂停, FALSE - 恢复</param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Agent_PauseReceive(IntPtr pAgent, IntPtr dwConnID, bool bPause);
- /// <summary>
- /// 断开某个连接
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="connId">连接 ID</param>
- /// <param name="bForce">是否强制断开连接</param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Agent_Disconnect(IntPtr pAgent, IntPtr connId, bool bForce);
- /// <summary>
- /// 断开超过指定时长的连接
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="dwPeriod">时长(毫秒)</param>
- /// <param name="bForce">是否强制断开连接</param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Agent_DisconnectLongConnections(IntPtr pAgent, uint dwPeriod, bool bForce);
- /// <summary>
- /// 断开超过指定时长的静默连接
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwPeriod">时长(毫秒)</param>
- /// <param name="bForce">是否强制断开连接</param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Agent_DisconnectSilenceConnections(IntPtr pAgent, uint dwPeriod, bool bForce);
- /******************************************************************************/
- /***************************** Agent 操作方法 *****************************/
- /// <summary>
- /// 名称:发送小文件
- /// 描述:向指定连接发送 4096 KB 以下的小文件
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="connId">连接 ID</param>
- /// <param name="lpszFileName">文件路径</param>
- /// <param name="pHead">头部附加数据</param>
- /// <param name="pTail">尾部附加数据</param>
- /// <returns>TRUE.成功 FALSE -- 失败,可通过 Windows API 函数 ::GetLastError() 获取 Windows 错误代码</returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_TcpAgent_SendSmallFile(IntPtr pAgent, IntPtr connId, string lpszFileName, ref WSABUF pHead, ref WSABUF pTail);
- /******************************************************************************/
- /***************************** Agent 属性访问方法 *****************************/
- /// <summary>
- /// 设置数据发送策略
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="enSendPolicy"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Agent_SetSendPolicy(IntPtr pAgent, SendPolicy enSendPolicy);
- /// <summary>
- /// 获取数据发送策略
- /// </summary>
- /// <param name="pAgent"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern SendPolicy HP_Agent_GetSendPolicy(IntPtr pAgent);
- /// <summary>
- /// 获取 OnSend 事件同步策略
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern OnSendSyncPolicy HP_Agent_GetOnSendSyncPolicy(IntPtr pAgent);
- /// <summary>
- /// 设置 OnSend 事件同步策略(默认:OSSP_NONE,不同步
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="syncPolicy"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Agent_SetOnSendSyncPolicy(IntPtr pAgent, OnSendSyncPolicy syncPolicy);
- /// <summary>
- /// 设置连接的附加数据
- /// 是否为连接绑定附加数据或者绑定什么样的数据,均由应用程序只身决定
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="connId">连接 ID</param>
- /// <param name="pExtra">数据</param>
- /// <returns>FALSE -- 失败(无效的连接 ID)</returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Agent_SetConnectionExtra(IntPtr pAgent, IntPtr connId, IntPtr pExtra);
- /// <summary>
- /// 获取连接的附加数据
- /// 是否为连接绑定附加数据或者绑定什么样的数据,均由应用程序只身决定
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="connId"></param>
- /// <param name="pExtra"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Agent_GetConnectionExtra(IntPtr pAgent, IntPtr connId, ref IntPtr pExtra);
- /// <summary>
- /// 检测是否为安全连接(SSL/HTTPS)
- /// </summary>
- /// <param name="pAgent"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Agent_IsSecure(IntPtr pAgent);
- /// <summary>
- /// 检查通信组件是否已启动
- /// </summary>
- /// <param name="pAgent"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Agent_HasStarted(IntPtr pAgent);
- /// <summary>
- /// 查看通信组件当前状态
- /// </summary>
- /// <param name="pAgent"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern ServiceState HP_Agent_GetState(IntPtr pAgent);
- /// <summary>
- /// 获取连接数
- /// </summary>
- /// <param name="pAgent"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_Agent_GetConnectionCount(IntPtr pAgent);
- /// <summary>
- /// 获取所有连接的 CONNID
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="pIDs"></param>
- /// <param name="pdwCount"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Agent_GetAllConnectionIDs(IntPtr pAgent, IntPtr[] pIDs, ref uint pdwCount);
- /// <summary>
- /// 获取某个连接时长(毫秒)
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="connId"></param>
- /// <param name="pdwPeriod"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Agent_GetConnectPeriod(IntPtr pAgent, IntPtr connId, ref uint pdwPeriod);
- /// <summary>
- /// 获取某个连接静默时间(毫秒)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="connId"></param>
- /// <param name="pdwPeriod"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Agent_GetSilencePeriod(IntPtr pAgent, IntPtr connId, ref uint pdwPeriod);
- /// <summary>
- /// 获取某个连接的本地地址信息
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="connId"></param>
- /// <param name="lpszAddress"></param>
- /// <param name="piAddressLen"></param>
- /// <param name="pusPort"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Agent_GetLocalAddress(IntPtr pAgent, IntPtr connId, [MarshalAs(UnmanagedType.LPStr)] StringBuilder lpszAddress, ref int piAddressLen, ref ushort pusPort);
- /// <summary>
- /// 获取某个连接的远程地址信息
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="connId"></param>
- /// <param name="lpszAddress"></param>
- /// <param name="piAddressLen"></param>
- /// <param name="pusPort"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Agent_GetRemoteAddress(IntPtr pAgent, IntPtr connId, [MarshalAs(UnmanagedType.LPStr)] StringBuilder lpszAddress, ref int piAddressLen, ref ushort pusPort);
- /// <summary>
- /// 获取某个连接的远程主机信息
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="dwConnID"></param>
- /// <param name="lpszAddress"></param>
- /// <param name="piHostLen"></param>
- /// <param name="pusPort"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Agent_GetRemoteHost(IntPtr pAgent, IntPtr dwConnID, [MarshalAs(UnmanagedType.LPStr)]StringBuilder lpszAddress, ref int piHostLen, ref ushort pusPort);
- /// <summary>
- /// 获取最近一次失败操作的错误代码
- /// </summary>
- /// <param name="pAgent"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern SocketError HP_Agent_GetLastError(IntPtr pAgent);
- /// <summary>
- /// 获取最近一次失败操作的错误描述
- /// </summary>
- /// <param name="pAgent"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr HP_Agent_GetLastErrorDesc(IntPtr pAgent);
- /// <summary>
- /// 获取连接中未发出数据的长度
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="connId"></param>
- /// <param name="piPending"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Agent_GetPendingDataLength(IntPtr pAgent, IntPtr connId, ref int piPending);
- /// <summary>
- /// 获取连接的数据接收状态
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="dwConnID"></param>
- /// <param name="pbPaused"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Agent_IsPauseReceive(IntPtr pAgent, IntPtr dwConnID, ref int pbPaused);
- /// <summary>
- /// 检测是否有效连接
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="dwConnID"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Agent_IsConnected(IntPtr pAgent, IntPtr dwConnID);
- /// <summary>
- /// 设置 Socket 缓存对象锁定时间(毫秒,在锁定期间该 Socket 缓存对象不能被获取使用)
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="dwFreeSocketObjLockTime"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Agent_SetFreeSocketObjLockTime(IntPtr pAgent, uint dwFreeSocketObjLockTime);
- /// <summary>
- /// 设置 Socket 缓存池大小(通常设置为平均并发连接数量的 1/3 - 1/2)
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="dwFreeSocketObjPool"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Agent_SetFreeSocketObjPool(IntPtr pAgent, uint dwFreeSocketObjPool);
- /// <summary>
- /// 设置内存块缓存池大小(通常设置为 Socket 缓存池大小的 2 - 3 倍)
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="dwFreeBufferObjPool"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Agent_SetFreeBufferObjPool(IntPtr pAgent, uint dwFreeBufferObjPool);
- /// <summary>
- /// 设置 Socket 缓存池回收阀值(通常设置为 Socket 缓存池大小的 3 倍)
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="dwFreeSocketObjHold"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Agent_SetFreeSocketObjHold(IntPtr pAgent, uint dwFreeSocketObjHold);
- /// <summary>
- /// 设置内存块缓存池回收阀值(通常设置为内存块缓存池大小的 3 倍)
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="dwFreeBufferObjHold"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Agent_SetFreeBufferObjHold(IntPtr pAgent, uint dwFreeBufferObjHold);
- /// <summary>
- /// 设置最大连接数(组件会根据设置值预分配内存,因此需要根据实际情况设置,不宜过大)
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="dwMaxConnectionCount"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Agent_SetMaxConnectionCount(IntPtr pAgent, uint dwMaxConnectionCount);
- /// <summary>
- /// 设置工作线程数量(通常设置为 2 * CPU + 2)
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="dwWorkerThreadCount"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Agent_SetWorkerThreadCount(IntPtr pAgent, uint dwWorkerThreadCount);
- /// <summary>
- /// 设置是否标记静默时间(设置为 TRUE 时 DisconnectSilenceConnections() 和 GetSilencePeriod() 才有效,默认:FALSE)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="bMarkSilence"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_Agent_SetMarkSilence(IntPtr pAgent, bool bMarkSilence);
- /// <summary>
- /// 获取 Socket 缓存对象锁定时间
- /// </summary>
- /// <param name="pAgent"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_Agent_GetFreeSocketObjLockTime(IntPtr pAgent);
- /// <summary>
- /// 获取 Socket 缓存池大小
- /// </summary>
- /// <param name="pAgent"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_Agent_GetFreeSocketObjPool(IntPtr pAgent);
- /// <summary>
- /// 获取内存块缓存池大小
- /// </summary>
- /// <param name="pAgent"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_Agent_GetFreeBufferObjPool(IntPtr pAgent);
- /// <summary>
- /// 获取 Socket 缓存池回收阀值
- /// </summary>
- /// <param name="pAgent"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_Agent_GetFreeSocketObjHold(IntPtr pAgent);
- /// <summary>
- /// 获取内存块缓存池回收阀值
- /// </summary>
- /// <param name="pAgent"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_Agent_GetFreeBufferObjHold(IntPtr pAgent);
- /// <summary>
- /// 获取最大连接数
- /// </summary>
- /// <param name="pAgent"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_Agent_GetMaxConnectionCount(IntPtr pAgent);
- /// <summary>
- /// 获取工作线程数量
- /// </summary>
- /// <param name="pAgent"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_Agent_GetWorkerThreadCount(IntPtr pAgent);
- /// <summary>
- /// 检测是否标记静默时间
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_Agent_IsMarkSilence(IntPtr pAgent);
- /**********************************************************************************/
- /***************************** TCP Agent 属性访问方法 *****************************/
- /// <summary>
- /// 置是否启用地址重用机制(默认:不启用)
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="bReuseAddress"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_TcpAgent_SetReuseAddress(IntPtr pAgent, bool bReuseAddress);
- /// <summary>
- /// 检测是否启用地址重用机制
- /// </summary>
- /// <param name="pAgent"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_TcpAgent_IsReuseAddress(IntPtr pAgent);
- /// <summary>
- /// 设置通信数据缓冲区大小(根据平均通信数据包大小调整设置,通常设置为 1024 的倍数)
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="dwSocketBufferSize"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_TcpAgent_SetSocketBufferSize(IntPtr pAgent, uint dwSocketBufferSize);
- /// <summary>
- /// 设置心跳包间隔(毫秒,0 则不发送心跳包)
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="dwKeepAliveTime"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_TcpAgent_SetKeepAliveTime(IntPtr pAgent, uint dwKeepAliveTime);
- /// <summary>
- /// 设置心跳确认包检测间隔(毫秒,0 不发送心跳包,如果超过若干次 [默认:WinXP 5 次, Win7 10 次] 检测不到心跳确认包则认为已断线)
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="dwKeepAliveInterval"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_TcpAgent_SetKeepAliveInterval(IntPtr pAgent, uint dwKeepAliveInterval);
- /// <summary>
- /// 获取通信数据缓冲区大小
- /// </summary>
- /// <param name="pAgent"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_TcpAgent_GetSocketBufferSize(IntPtr pAgent);
- /// <summary>
- /// 获取心跳检查次数
- /// </summary>
- /// <param name="pAgent"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_TcpAgent_GetKeepAliveTime(IntPtr pAgent);
- /// <summary>
- /// 获取心跳检查间隔
- /// </summary>
- /// <param name="pAgent"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_TcpAgent_GetKeepAliveInterval(IntPtr pAgent);
- /***************************************************************************************/
- /***************************** TCP Pull Server 组件操作方法 *****************************/
- /// <summary>
- /// 抓取数据
- /// 用户通过该方法从 Socket 组件中抓取数据
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="connId">连接 ID</param>
- /// <param name="pBuffer">数据抓取缓冲区</param>
- /// <param name="length">抓取数据长度</param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern FetchResult HP_TcpPullServer_Fetch(IntPtr pServer, IntPtr connId, IntPtr pBuffer, int length);
- /// <summary>
- /// 窥探数据(不会移除缓冲区数据)
- /// 描述:用户通过该方法从 Socket 组件中窥探数据
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="connId">连接 ID</param>
- /// <param name="pBuffer">窥探缓冲区</param>
- /// <param name="length">窥探数据长度</param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern FetchResult HP_TcpPullServer_Peek(IntPtr pServer, IntPtr connId, IntPtr pBuffer, int length);
- /***************************************************************************************/
- /***************************** TCP Pull Server 属性访问方法 *****************************/
- /***************************************************************************************/
- /***************************** TCP Pull Client 组件操作方法 *****************************/
- /// <summary>
- /// 抓取数据
- /// 用户通过该方法从 Socket 组件中抓取数据
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="connId">连接 ID</param>
- /// <param name="pBuffer">数据抓取缓冲区</param>
- /// <param name="length">抓取数据长度</param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern FetchResult HP_TcpPullClient_Fetch(IntPtr pClient, IntPtr pBuffer, int length);
- /// <summary>
- /// 名称:窥探数据(不会移除缓冲区数据)
- /// 描述:用户通过该方法从 Socket 组件中窥探数据
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="connId">连接 ID</param>
- /// <param name="pBuffer">数据抓取缓冲区</param>
- /// <param name="length">抓取数据长度</param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern FetchResult HP_TcpPullClient_Peek(IntPtr pClient, IntPtr pBuffer, int length);
- /***************************************************************************************/
- /***************************** TCP Pull Client 属性访问方法 *****************************/
- /***************************************************************************************/
- /***************************** TCP Pull Agent 组件操作方法 *****************************/
- /// <summary>
- /// 抓取数据
- /// 用户通过该方法从 Socket 组件中抓取数据
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="connId">连接 ID</param>
- /// <param name="pBuffer">数据抓取缓冲区</param>
- /// <param name="length">抓取数据长度</param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern FetchResult HP_TcpPullAgent_Fetch(IntPtr pAgent, IntPtr connId, IntPtr pBuffer, int length);
- /// <summary>
- /// 名称:窥探数据(不会移除缓冲区数据)
- /// 描述:用户通过该方法从 Socket 组件中窥探数据
- /// </summary>
- /// <param name="pAgent"></param>
- /// <param name="connId">连接 ID</param>
- /// <param name="pBuffer">数据抓取缓冲区</param>
- /// <param name="length">抓取数据长度</param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern FetchResult HP_TcpPullAgent_Peek(IntPtr pAgent, IntPtr connId, IntPtr pBuffer, int length);
- /***************************************************************************************/
- /***************************** TCP Pull Agent 属性访问方法 *****************************/
- /***************************************************************************************/
- /***************************************************************************************/
- /***************************** TCP Pack Server 组件操作方法 *****************************/
- /***************************************************************************************/
- /***************************** TCP Pack Server 属性访问方法 *****************************/
- /// <summary>
- /// 设置数据包最大长度(有效数据包最大长度不能超过 4194303/0x3FFFFF 字节,默认:262144/0x40000)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwMaxPackSize">有效数据包最大长度不能超过 4194303/0x3FFFFF 字节,默认:262144/0x40000</param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_TcpPackServer_SetMaxPackSize(IntPtr pServer, uint dwMaxPackSize);
- /// <summary>
- /// 设置包头标识(有效包头标识取值范围 0 ~ 1023/0x3FF,当包头标识为 0 时不校验包头,默认:0)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="usPackHeaderFlag">有效包头标识取值范围 0 ~ 1023/0x3FF,当包头标识为 0 时不校验包头,默认:0</param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_TcpPackServer_SetPackHeaderFlag(IntPtr pServer, ushort usPackHeaderFlag);
- /// <summary>
- /// 获取数据包最大长度
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_TcpPackServer_GetMaxPackSize(IntPtr pServer);
- /// <summary>
- /// 获取包头标识
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern ushort HP_TcpPackServer_GetPackHeaderFlag(IntPtr pServer);
- /***************************************************************************************/
- /***************************** TCP Pack Agent 组件操作方法 *****************************/
- /***************************************************************************************/
- /***************************** TCP Pack Agent 属性访问方法 *****************************/
- /// <summary>
- /// 设置数据包最大长度(有效数据包最大长度不能超过 524287/0x7FFFF 字节,默认:262144/0x40000)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwMaxPackSize">有效数据包最大长度不能超过 524287/0x7FFFF 字节,默认:262144/0x40000</param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_TcpPackAgent_SetMaxPackSize(IntPtr pAgent, uint dwMaxPackSize);
- /// <summary>
- /// 设置包头标识(有效包头标识取值范围 0 ~ 8191/0x1FFF,当包头标识为 0 时不校验包头,默认:0)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="usPackHeaderFlag">有效包头标识取值范围 0 ~ 8191/0x1FFF,当包头标识为 0 时不校验包头,默认:0</param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_TcpPackAgent_SetPackHeaderFlag(IntPtr pAgent, ushort usPackHeaderFlag);
- /// <summary>
- /// 获取数据包最大长度
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_TcpPackAgent_GetMaxPackSize(IntPtr pAgent);
- /// <summary>
- /// 获取包头标识
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern ushort HP_TcpPackAgent_GetPackHeaderFlag(IntPtr pAgent);
- /***************************************************************************************/
- /***************************** TCP Pack Client 组件操作方法 *****************************/
- /***************************************************************************************/
- /***************************** TCP Pack Client 属性访问方法 *****************************/
- /// <summary>
- /// 设置数据包最大长度(有效数据包最大长度不能超过 524287/0x7FFFF 字节,默认:262144/0x40000)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwMaxPackSize">有效数据包最大长度不能超过 524287/0x7FFFF 字节,默认:262144/0x40000</param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_TcpPackClient_SetMaxPackSize(IntPtr pClient, uint dwMaxPackSize);
- /// <summary>
- /// 设置包头标识(有效包头标识取值范围 0 ~ 8191/0x1FFF,当包头标识为 0 时不校验包头,默认:0)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="usPackHeaderFlag">有效包头标识取值范围 0 ~ 8191/0x1FFF,当包头标识为 0 时不校验包头,默认:0</param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_TcpPackClient_SetPackHeaderFlag(IntPtr pClient, ushort usPackHeaderFlag);
- /// <summary>
- /// 获取数据包最大长度
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_TcpPackClient_GetMaxPackSize(IntPtr pClient);
- /// <summary>
- /// 获取包头标识
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern ushort HP_TcpPackClient_GetPackHeaderFlag(IntPtr pClient);
- /***************************************************************************************/
- /*************************************** 其它方法 ***************************************/
- /// <summary>
- /// 获取 HPSocket 版本号(4 个字节分别为:主版本号,子版本号,修正版本号,构建编号)
- /// </summary>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_GetHPSocketVersion();
- /// <summary>
- /// 获取版本号
- /// </summary>
- /// <returns></returns>
- public static string GetHPSocketVersion()
- {
- /*
- var ver = BitConverter.GetBytes(HP_GetHPSocketVersion());
- var major = ver[3];
- var minor = ver[2];
- var revision = ver[1];
- var build = ver[0];*/
- uint ver = HP_GetHPSocketVersion();
- var major = ver >> 24;
- var minor = (ver << 8) >> 24;
- var revision = (ver << 16) >> 24;
- var build = (ver << 24) >> 24;
- return string.Format("{0}.{1}.{2}_{3}", major, minor, revision, build);
- }
- /// <summary>
- /// 获取错误描述文本
- /// </summary>
- /// <param name="enCode"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr HP_GetSocketErrorDesc(SocketError enCode);
- /// <summary>
- /// 调用系统的 ::GetLastError() 方法获取系统错误代码
- /// </summary>
- /// <returns></returns>
- public static int SYS_GetLastError()
- {
- return Marshal.GetLastWin32Error();
- }
- /// <summary>
- /// 调用系统的 ::WSAGetLastError() 方法获取通信错误代码
- /// </summary>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern int SYS_WSAGetLastError();
- /// <summary>
- /// 调用系统的 setsockopt()
- /// </summary>
- /// <param name="sock"></param>
- /// <param name="level"></param>
- /// <param name="name"></param>
- /// <param name="val"></param>
- /// <param name="len"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern int SYS_SetSocketOption(IntPtr sock, int level, int name, IntPtr val, int len);
- /// <summary>
- /// 调用系统的 getsockopt()
- /// </summary>
- /// <param name="sock"></param>
- /// <param name="level"></param>
- /// <param name="name"></param>
- /// <param name="val"></param>
- /// <param name="len"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern int SYS_GetSocketOption(IntPtr sock, int level, int name, IntPtr val, ref int len);
- /// <summary>
- /// 调用系统的 ioctlsocket()
- /// </summary>
- /// <param name="sock"></param>
- /// <param name="cmd"></param>
- /// <param name="arg"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern int SYS_IoctlSocket(IntPtr sock, long cmd, IntPtr arg);
- /// <summary>
- /// 调用系统的 ::WSAIoctl()
- /// </summary>
- /// <param name="sock"></param>
- /// <param name="dwIoControlCode"></param>
- /// <param name="lpvInBuffer"></param>
- /// <param name="cbInBuffer"></param>
- /// <param name="lpvOutBuffer"></param>
- /// <param name="cbOutBuffer"></param>
- /// <param name="lpcbBytesReturned"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern int SYS_WSAIoctl(IntPtr sock, uint dwIoControlCode, IntPtr lpvInBuffer, uint cbInBuffer,
- IntPtr lpvOutBuffer, uint cbOutBuffer, uint lpcbBytesReturned);
- /// <summary>
- /// 设置 socket 选项:IPPROTO_TCP -> TCP_NODELAY
- /// </summary>
- /// <param name="sock"></param>
- /// <param name="bNoDelay"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern int SYS_SSO_NoDelay(IntPtr sock, bool bNoDelay);
- /// <summary>
- /// 设置 socket 选项:SOL_SOCKET -> SO_DONTLINGER
- /// </summary>
- /// <param name="sock"></param>
- /// <param name="bDont"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern int SYS_SSO_DontLinger(IntPtr sock, bool bDont);
- /// <summary>
- /// 设置 socket 选项:SOL_SOCKET -> SO_LINGER
- /// </summary>
- /// <param name="sock"></param>
- /// <param name="l_onoff"></param>
- /// <param name="l_linger"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern int SYS_SSO_Linger(IntPtr sock, ushort l_onoff, ushort l_linger);
- /// <summary>
- /// 设置 socket 选项:SOL_SOCKET -> SO_RCVBUF
- /// </summary>
- /// <param name="sock"></param>
- /// <param name="size"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern int SYS_SSO_RecvBuffSize(IntPtr sock, int size);
- /// <summary>
- /// 设置 socket 选项:SOL_SOCKET -> SO_SNDBUF
- /// </summary>
- /// <param name="sock"></param>
- /// <param name="size"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern int SYS_SSO_SendBuffSize(IntPtr sock, int size);
- /// <summary>
- /// 设置 socket 选项:SOL_SOCKET -> SO_REUSEADDR
- /// </summary>
- /// <param name="sock"></param>
- /// <param name="bReuse"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern int SYS_SSO_ReuseAddress(IntPtr sock, bool bReuse);
- /// <summary>
- /// 获取 SOCKET 本地地址信息
- /// </summary>
- /// <param name="pSocket"></param>
- /// <param name="lpszAddress"></param>
- /// <param name="piAddressLen">传入传出值,大小最好在222.222.222.222的长度以上</param>
- /// <param name="pusPort"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool SYS_GetSocketLocalAddress(IntPtr pSocket, [MarshalAs(UnmanagedType.LPStr)] StringBuilder lpszAddress, ref int piAddressLen, ref ushort pusPort);
- /// <summary>
- /// 获取 SOCKET 远程地址信息
- /// </summary>
- /// <param name="pSocket"></param>
- /// <param name="lpszAddress"></param>
- /// <param name="piAddressLen">传入传出值,大小最好在222.222.222.222的长度以上</param>
- /// <param name="pusPort"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool SYS_GetSocketRemoteAddress(IntPtr pSocket, [MarshalAs(UnmanagedType.LPStr)] StringBuilder lpszAddress, ref int piAddressLen, ref ushort pusPort);
- /// <summary>
- /// 枚举主机 IP 地址
- /// 不要用,未测试
- /// 不要用,未测试
- /// 不要用,未测试
- /// </summary>
- /// <param name="lpszHost"></param>
- /// <param name="enType"></param>
- /// <param name="lpppIPAddr"></param>
- /// <param name="piIPAddrCount"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool SYS_EnumHostIPAddresses(string lpszHost, IPAddrType enType, ref IntPtr lpppIPAddr, ref int piIPAddrCount);
- /// <summary>
- /// 释放 HP_LPTIPAddr
- /// </summary>
- /// <param name="lppIPAddr"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool SYS_FreeHostIPAddresses(IntPtr lppIPAddr);
- /*
- * 已删除
- /// <summary>
- /// 获取 IPv4 地址
- /// </summary>
- /// <param name="lpszAddress"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint SYS_GetIPv4InAddr(string lpszAddress);
- */
- /// <summary>
- /// 检查字符串是否符合 IP 地址格式
- /// </summary>
- /// <param name="lpszAddress"></param>
- /// <param name="penType"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool SYS_IsIPAddress(string lpszAddress, ref IPAddrType penType);
- /// <summary>
- /// 通过主机名获取 IP 地址
- /// </summary>
- /// <param name="lpszHost"></param>
- /// <param name="lpszIP"></param>
- /// <param name="piIPLenth"></param>
- /// <param name="penType"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool SYS_GetIPAddress(string lpszHost, [MarshalAs(UnmanagedType.LPStr)] StringBuilder lpszIP, ref int piIPLenth, ref IPAddrType penType);
- /*
- * 已删除
- /// <summary>
- /// 通过主机名获取最优的 IP 地址
- /// </summary>
- /// <param name="lpszHost"></param>
- /// <param name="pulAddr"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool SYS_GetOptimalIPByHostName(string lpszHost, ref uint pulAddr);
- */
- /// <summary>
- /// 64 位网络字节序转主机字节序
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern ulong SYS_NToH64(ulong value);
- /// <summary>
- /// 64 位主机字节序转网络字节序
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern ulong SYS_HToN64(ulong value);
- /// <summary>
- /// 分配内存
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr SYS_Malloc(int value);
- /// <summary>
- /// 重新分配内存
- /// </summary>
- /// <param name="p"></param>
- /// <param name="value"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr SYS_Realloc(IntPtr p, int value);
- /// <summary>
- /// 释放内存
- /// </summary>
- /// <param name="p"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void SYS_Free(IntPtr p);
- /// <summary>
- /// 创建 HP_UdpArqServer 对象
- /// </summary>
- /// <param name="pListener"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_UdpArqServer(IntPtr pListener);
- /// <summary>
- /// 创建 HP_UdpArqClient 对象
- /// </summary>
- /// <param name="pListener"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_UdpArqClient(IntPtr pListener);
- /// <summary>
- /// 销毁 HP_UdpArqServer 对象
- /// </summary>
- /// <param name="pServer"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_UdpArqServer(IntPtr pServer);
- /// <summary>
- /// 销毁 HP_UdpArqClient 对象
- /// </summary>
- /// <param name="pClient"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_UdpArqClient(IntPtr pClient);
- /// <summary>
- /// 创建 HP_UdpArqServerListener 对象
- /// </summary>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_UdpArqServerListener();
- /// <summary>
- /// 创建 HP_UdpArqClientListener 对象
- /// </summary>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern IntPtr Create_HP_UdpArqClientListener();
- /// <summary>
- /// 销毁 HP_UdpArqServerListener 对象
- /// </summary>
- /// <param name="pListener"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_UdpArqServerListener(IntPtr pListener);
- /// <summary>
- /// 销毁 HP_UdpArqClientListener 对象
- /// </summary>
- /// <param name="pListener"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void Destroy_HP_UdpArqClientListener(IntPtr pListener);
- /**********************************************************************************/
- /*************************** UDP ARQ Server 属性访问方法 ***************************/
- /// <summary>
- /// 设置是否开启 nodelay 模式(默认:FALSE,不开启)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="bNoDelay"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpArqServer_SetNoDelay(IntPtr pServer, bool bNoDelay);
- /// <summary>
- /// 设置是否关闭拥塞控制(默认:FALSE,不关闭)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="bTurnOff"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpArqServer_SetTurnoffCongestCtrl(IntPtr pServer, bool bTurnOff);
- /// <summary>
- /// 设置数据刷新间隔(毫秒,默认:20)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwFlushInterval"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpArqServer_SetFlushInterval(IntPtr pServer, uint dwFlushInterval);
- /// <summary>
- /// 设置快速重传 ACK 跨越次数(默认:0,关闭快速重传)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwResendByAcks"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpArqServer_SetResendByAcks(IntPtr pServer, uint dwResendByAcks);
- /// <summary>
- /// 设置发送窗口大小(数据包数量,默认:128)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwSendWndSize"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpArqServer_SetSendWndSize(IntPtr pServer, uint dwSendWndSize);
- /// <summary>
- /// 设置接收窗口大小(数据包数量,默认:512)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwRecvWndSize"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpArqServer_SetRecvWndSize(IntPtr pServer, uint dwRecvWndSize);
- /// <summary>
- /// 设置最小重传超时时间(毫秒,默认:30)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwMinRto"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpArqServer_SetMinRto(IntPtr pServer, uint dwMinRto);
- /// <summary>
- /// 设置最大传输单元(默认:0,与 SetMaxDatagramSize() 一致)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwMaxTransUnit"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpArqServer_SetMaxTransUnit(IntPtr pServer, uint dwMaxTransUnit);
- /// <summary>
- /// 设置最大数据包大小(默认:4096)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwMaxMessageSize"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpArqServer_SetMaxMessageSize(IntPtr pServer, uint dwMaxMessageSize);
- /// <summary>
- /// 设置握手超时时间(毫秒,默认:5000)
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwHandShakeTimeout"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpArqServer_SetHandShakeTimeout(IntPtr pServer, uint dwHandShakeTimeout);
- /// <summary>
- /// 检测是否开启 nodelay 模式
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_UdpArqServer_IsNoDelay(IntPtr pServer);
- /// <summary>
- /// 检测是否关闭拥塞控制
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_UdpArqServer_IsTurnoffCongestCtrl(IntPtr pServer);
- /// <summary>
- /// 获取数据刷新间隔
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_UdpArqServer_GetFlushInterval(IntPtr pServer);
- /// <summary>
- /// 获取快速重传 ACK 跨越次数
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_UdpArqServer_GetResendByAcks(IntPtr pServer);
- /// <summary>
- /// 获取发送窗口大小
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_UdpArqServer_GetSendWndSize(IntPtr pServer);
- /// <summary>
- /// 获取接收窗口大小
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_UdpArqServer_GetRecvWndSize(IntPtr pServer);
- /// <summary>
- /// 获取最小重传超时时间
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_UdpArqServer_GetMinRto(IntPtr pServer);
- /// <summary>
- /// 获取最大传输单元
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_UdpArqServer_GetMaxTransUnit(IntPtr pServer);
- /// <summary>
- /// 获取最大数据包大小
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_UdpArqServer_GetMaxMessageSize(IntPtr pServer);
- /// <summary>
- /// 获取握手超时时间
- /// </summary>
- /// <param name="pServer"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_UdpArqServer_GetHandShakeTimeout(IntPtr pServer);
- /// <summary>
- /// 获取等待发送包数量
- /// </summary>
- /// <param name="pServer"></param>
- /// <param name="dwConnId"></param>
- /// <param name="piCount"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_UdpArqServer_GetWaitingSendMessageCount(IntPtr pServer, IntPtr dwConnId, ref int piCount);
- /**********************************************************************************/
- /*************************** UDP ARQ Client 属性访问方法 ***************************/
- /// <summary>
- /// 设置是否开启 nodelay 模式(默认:FALSE,不开启)
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="bNoDelay"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpArqClient_SetNoDelay(IntPtr pClient, bool bNoDelay);
- /// <summary>
- /// 设置是否关闭拥塞控制(默认:FALSE,不关闭)
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="bTurnOff"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpArqClient_SetTurnoffCongestCtrl(IntPtr pClient, bool bTurnOff);
- /// <summary>
- /// 设置数据刷新间隔(毫秒,默认:20)
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="dwFlushInterval"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpArqClient_SetFlushInterval(IntPtr pClient, uint dwFlushInterval);
- /// <summary>
- /// 设置快速重传 ACK 跨越次数(默认:0,关闭快速重传)
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="dwResendByAcks"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpArqClient_SetResendByAcks(IntPtr pClient, uint dwResendByAcks);
- /// <summary>
- /// 设置发送窗口大小(数据包数量,默认:128)
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="dwSendWndSize"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpArqClient_SetSendWndSize(IntPtr pClient, uint dwSendWndSize);
- /// <summary>
- /// 设置接收窗口大小(数据包数量,默认:512)
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="dwRecvWndSize"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpArqClient_SetRecvWndSize(IntPtr pClient, uint dwRecvWndSize);
- /// <summary>
- /// 设置最小重传超时时间(毫秒,默认:30)
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="dwMinRto"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpArqClient_SetMinRto(IntPtr pClient, uint dwMinRto);
- /// <summary>
- /// 设置最大传输单元(默认:0,与 SetMaxDatagramSize() 一致)
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="dwMaxTransUnit"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpArqClient_SetMaxTransUnit(IntPtr pClient, uint dwMaxTransUnit);
- /// <summary>
- /// 设置最大数据包大小(默认:4096)
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="dwMaxMessageSize"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpArqClient_SetMaxMessageSize(IntPtr pClient, uint dwMaxMessageSize);
- /// <summary>
- /// 设置握手超时时间(毫秒,默认:5000)
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="dwHandShakeTimeout"></param>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern void HP_UdpArqClient_SetHandShakeTimeout(IntPtr pClient, uint dwHandShakeTimeout);
- /// <summary>
- /// 检测是否开启 nodelay 模式
- /// </summary>
- /// <param name="pClient"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_UdpArqClient_IsNoDelay(IntPtr pClient);
- /// <summary>
- /// 检测是否关闭拥塞控制
- /// </summary>
- /// <param name="pClient"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_UdpArqClient_IsTurnoffCongestCtrl(IntPtr pClient);
- /// <summary>
- /// 获取数据刷新间隔
- /// </summary>
- /// <param name="pClient"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_UdpArqClient_GetFlushInterval(IntPtr pClient);
- /// <summary>
- /// 获取快速重传 ACK 跨越次数
- /// </summary>
- /// <param name="pClient"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_UdpArqClient_GetResendByAcks(IntPtr pClient);
- /// <summary>
- /// 获取发送窗口大小
- /// </summary>
- /// <param name="pClient"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_UdpArqClient_GetSendWndSize(IntPtr pClient);
- /// <summary>
- /// 获取接收窗口大小
- /// </summary>
- /// <param name="pClient"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_UdpArqClient_GetRecvWndSize(IntPtr pClient);
- /// <summary>
- /// 获取最小重传超时时间
- /// </summary>
- /// <param name="pClient"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_UdpArqClient_GetMinRto(IntPtr pClient);
- /// <summary>
- /// 获取最大传输单元
- /// </summary>
- /// <param name="pClient"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_UdpArqClient_GetMaxTransUnit(IntPtr pClient);
- /// <summary>
- /// 获取最大数据包大小
- /// </summary>
- /// <param name="pClient"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_UdpArqClient_GetMaxMessageSize(IntPtr pClient);
- /// <summary>
- /// 获取握手超时时间
- /// </summary>
- /// <param name="pClient"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern uint HP_UdpArqClient_GetHandShakeTimeout(IntPtr pClient);
- /// <summary>
- /// 获取等待发送包数量
- /// </summary>
- /// <param name="pClient"></param>
- /// <param name="piCount"></param>
- /// <returns></returns>
- [DllImport(HPSOCKET_DLL_PATH, CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern bool HP_UdpArqClient_GetWaitingSendMessageCount(IntPtr pClient, ref int piCount);
- }
|