(转)hp socket 5.8.2 高性能网络扩展库

By admin at 2021-03-25 • 0人收藏 • 2501人看过

感谢: fish 分享


aardio的扩展库里已经有个jacenHe提供的HPsocket库,位置如下:

image.png


此次分享的是由fish封装的, 目前只封装了 ssl http client 部分, 测试例子在 simple 目录下.

https://github.com/btx638/HP-Socket-bindings-for-aardio

有需要的可以学习下.


aaz.libhpsocket.7z


image.png

使用例子代码如下:

import win.ui;
/*DSG{{*/
var winform = win.form(text="aardio form";right=466;bottom=144)
winform.add(
btnBaidu={cls="button";text="访问 baidu";left=25;top=16;right=156;bottom=47;z=2};
btnCnbeta={cls="button";text="访问 cnbeta";left=176;top=17;right=307;bottom=48;z=3};
edInfo={cls="edit";text="网页源码保存在同目录的  test.html";left=208;top=89;right=423;bottom=116;edge=1;multiline=1;readonly=1;z=1}
)
/*}}*/

io.open()

import aaz.libhpsocket.ssl.listener.httpClient;

var listener = aaz.libhpsocket.ssl.listener.httpClient();
var component = listener.createComponent();

listener.onPrepareConnect = function(component, connId, soListen){
	io.print("[onPrepareConnect]", connId, soListen)
}

listener.onConnect = function(component, connId){
	io.print("[onConnect]", connId)
} 

listener.onHandShake = function(component, connId){
	io.print("[onHandShake]", connId)
}

// 开始解析
listener.onMessageBegin = function(component, connId){
	io.print("[onMessageBegin]", component, connId)
	component.reallocString(1)
}

// 状态行解析完成 (仅用于 HTTP 客户端)
listener.onStatusLine = function(component, connId, usStatusCode, lpszDesc){
	io.print("[onStatusLine]", component, connId, usStatusCode,  lpszDesc )
}

// 请求头
listener.onHeader = function(component, connId, pszName, lpszValue){
	io.print("[onHeader]", component, connId, pszName, lpszValue)
}

// 请求头完成
listener.onHeadersComplete = function(component, connId){
	io.print("[onHeadersComplete]", component, connId)
	
	if(component.getHeader("Transfer-Encoding") == "chunked"){
		io.print("[onHeadersComplete]->分块传输")
	}
	else {
		io.print("[onHeadersComplete]->content-length", component.contentLength)
	}
		
	io.print("------all headers-----------")
	var headers = component.getAllHeaders()
	for(i=1;#headers;1){
		io.print( headers[i].name, headers[i].value )
	}
	
	io.print("------headers-----------")
	var headers = component.getHeaders("Set-Cookie");
	for(i=1;#headers;1){
		io.print(headers[i])
	}	
	
	io.print("------all cookies-----------")
	var cookies = component.getAllCookies()
	for(i=1;#cookies;1){
		io.print( cookies[i].name, cookies[i].value )
	}	
}

// Chunked 报文头
listener.onChunkHeader = function(component, connId, iLength){
	io.print("[onChunkHeader]", component, connId, iLength)
}

// Chunked 报文结束
listener.onChunkComplete = function(component, connId){
	io.print("[onChunkComplete]", component, connId)
}

// BODY 报文
listener.onBody = function(component, connId, pData, len){
	io.print("[onBody]", component, connId, pData, len)
	component.appendString(pData, len)
}

// 完成解析
listener.onMessageComplete = function(component, connId){
	io.print("[onMessageComplete]", component, connId)
	
	var html = component.getString();
	string.save("\test.html", html)
}

// 升级协议
listener.onUpgrade = function(component, connId, enUpgradeType){
	io.print("[onUpgrade]", component, connId, enUpgradeType)
}

// 解析错误
listener.onParseError = function(component, connId, iErrorCode, lpszErrorDesc){
	io.print("[onParseError]", component, connId, iErrorCode, lpszErrorDesc)
}

// Web Socket 数据包头
listener.onWsMessageHeader = function(component, connId, bFinal, iReserved, iOperationCode, lpszMask, ullBodyLen){
	io.print("[onWsMessageHeader]", component, connId, bFinal, iReserved, iOperationCode, lpszMask, ullBodyLen)
}

// Web Socket 数据包体
listener.onWsMessageBody = function(component, connId, pData, iLength){
	io.print("[onWsMessageBody]", component, connId, pData, iLength)
}

// Web Socket 数据包体
listener.onWsMessageComplete = function(component, connId){
	io.print("[onWsMessageComplete]", component, connId)
}

listener.onClose = function(component, connId){
	io.print("[onClose]", component, connId)
	component.reallocString(0)
}

component.setupSSLContext()

winform.btnCnbeta.oncommand = function(id,event){
	component.start("www.cnbeta.com",443)
	
	// 自己想办法在触发 onHandShake 事件后才运行
	component.sendGet(
		"/",
    	{
    		["user-agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36";
    		["accept-language"] = "zh-CN,zh;q=0.9,ja;q=0.8,zh-TW;q=0.7";  
		}
	)
}

winform.btnBaidu.oncommand = function(id,event){
	component.start("www.baidu.com",443)
	
	// 自己想办法在触发 onHandShake 事件后才运行
	component.sendGet(
		"/",
    	{
    		["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9";
    		["user-agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36";
    		["accept-language"] = "zh-CN,zh;q=0.9,ja;q=0.8,zh-TW;q=0.7";  
		}
	)	
}

winform.show();
win.loopMessage();





9 个回复 | 最后更新于 2022-04-24
2021-04-04   #1

感谢回复,已删除 thread.callbackInitialize 相关代码

2021-08-19   #2

修改了 HPSocket 的源代码增加OnWorkerThreadEnd事件部分的代码能提供么

2021-08-19   #3

https://github.com/aardio/HP-Socket 已经不可以访问

2021-08-20   #4

回复#4 @txhelp :

自己在扩展库里更新下载啊

随便找个文本处理软件搜下就看到了

image.png

2021-08-20   #5

回复#5 @admin :

他可能问的是 HPSocket ”中的  添加的 OnWorkerThreadEnd 部分的代码

2021-08-20   #6

对, 是修改的c 源码的部分

2021-12-15   #7

回复#3 @txhelp :

理论上可以通过  ..subscribe("beforeUnload")  来执行释放 COM 套间函数,


可以加入开黑啦群讨论这个库的使用 https://kaihei.co/7bZDKE

2022-01-11   #8

hp socket 说已经提供了 线程池组件的方案,包含了 OnWorkerThreadStart/End的接口

具体看 https://github.com/ldcsaa/HP-Socket/issues/205#issuecomment-1001312752


API 位置 https://github.com/ldcsaa/HP-Socket/blob/dev/Windows/Include/HPSocket/HPSocket4C.h#L2558


捕获.PNG

2022-04-24   #9

回复#11 @terrorist :

新版本hpsocket.dll提供的线程池组件与socket(server,client等)组件线程回调无关,只是帮助我们创建管理自己的线程池,与socket组件的线程并不是同一个池子,所以并没有实现我们需要的onThreadEnd事件。既然onThreadEnd没有实现,那为什么aardio中的hp库能监测onThreadStart呢?其实也不能监控,只是大佬换了一个思路,用一个global变量在首次回调触发时当成onThreadStart来处理。我们也没必要纠结这个点,只要在使用com前主动调用thread.callbackInitialize,使用完com后再调用 thread.callbackUninitialize

登录后方可回帖

登 录
信息栏
 私人小站

本站域名

ChengXu.XYZ

投诉联系:  popdes@126.com



快速上位机开发学习,本站主要记录了学习过程中遇到的问题和解决办法及上位机代码分享

这里主要专注于学习交流和经验分享.
纯私人站,当笔记本用的,学到哪写到哪.
如果侵权,联系 Popdes@126.com

友情链接
Aardio官方
Aardio资源网


才仁机械


网站地图SiteMap

Loading...