记录下使用woo语言开发 sockets 和https代理过程
已经在gitee开源: https://gitee.com/oshine/woo_proxy
目前使用的是一个端口监听所有的代理包含http https sockets4 sockets5
作为程序员,当克隆时候速度蚂蚁一般真的没地儿诉苦
好了废话不多说,上代码:
1.启动服务监听端口
client.woo 文件内容:
_DIR = _DIR == '.' and './' or _DIR
local conf = require(_DIR .. '.conf')
local addr = conf['http/s_sockets4/5_addr']
print('sockets(4/5) and http/s proxy start on:', addr)
local ser = woo.sockets:new()
-- 开启 tcp sockets proxy监听服务
ser:listen('tcp', addr, function(handler)
-- 启动一个线程来处理,启动线程需要绝对路径
_run(_DIR .. '/client/sockets_handler.woo', handler, _DIR, conf) -- 把sockets handler,目录位置传入线程中去
end, function(err)
print(err)
end)
2.handler文件内容:
require(_ARGS[2] .. '.client.utils'); -- 导入工具包
local conf = _ARGS[3];
print('sockets(4/5) handler in:')
_out('_ARGS:=== ', _ARGS);
(function()
-- 获取线程传入的 sockets handler
local handler = _ARGS[1]
assert(handler, 'server form parent not correct.')
print('conn ok!')
local len, b = handler:read(1)
if len < 1 then
print("Request packet is too short!")
return
end
print('Got first byre for proxy:', b[1])
if b[