dosgo / ngrok-c

ngrok client for c language,Due to the use of GO ngrok language development, porting to embedded devices some inconvenience, such as openwrt, so use C language rewrite a client. Very mini, the need to support polarssl library.
MIT License
496 stars 203 forks source link

关于断线重连的问题 #19

Closed kwxiaozhu closed 6 years ago

kwxiaozhu commented 8 years ago

我在用ngrok-c的过程中发现,有时ngrok服务器重启或者ngrokd进程死掉后,再启动ngrokd时,发现ngrok-c不能自动重新建立通道,如果正常使用中断网又恢复后,能否自动重连?

dosgo commented 8 years ago

版本,1.32版本没问题,1.24也没问题。。中间的有bug。还有自动连接有60ms延迟。。避免频繁重试。。

kwxiaozhu commented 8 years ago

1.32版本mips版……刚才没等到60s,现在的问题是tcp通道已经正常重连,http通道显示重连,但是端口不对,我这边的环境是我自己架设的ngrokd服务器,http和https是8081和8082端口,我使用nginx反代到80端口使用,正常情况下使用ngrok-c建立http通道后,返回的是8081端口的连接,但是当断线重连后却直接返回了80端口的URL,直接访问提示Tunnel :8081 not found,是nginx配置的原因吗,但是应该和nginx没关系吧。

kwxiaozhu commented 8 years ago

{"Type":"AuthResp","Payload":{"Version":"2","MmVersion":"1.7","ClientId":"1728f23aa84f6309aa07ba069552804c","Error":""}} {"Type":"ReqProxy","Payload":{}} {"Type":"Pong","Payload":{}} {"Type":"Pong","Payload":{}} {"Type":"NewTunnel","Payload":{"ReqId":"NWLRB","Url":"tcp://mydomain.pw:39611","Protocol":"tcp","Error":""}} Add tunnel ok,type:tcp url:tcp://mydomain.pw:39611 {"Type":"NewTunnel","Payload":{"ReqId":"BMQBH","Url":"http://mydomain.pw:8081","Protocol":"http","Error":""}} Add tunnel ok,type:http url:http://mydomain.pw:8081 {"Type":"AuthResp","Payload":{"Version":"2","MmVersion":"1.7","ClientId":"1728f23aa84f6309aa07ba069552804c","Error":""}} {"Type":"ReqProxy","Payload":{}} {"Type":"Pong","Payload":{}} {"Type":"Pong","Payload":{}} {"Type":"NewTunnel","Payload":{"ReqId":"CDARZ","Url":"tcp://mydomain.pw:39611","Protocol":"tcp","Error":""}} Add tunnel ok,type:tcp url:tcp://mydomain.pw:39611 {"Type":"NewTunnel","Payload":{"ReqId":"OWKKY","Url":"http:/mydomain.pw","Protocol":"http","Error":""}} Add tunnel ok,type:http url:http://mydomain.pw

dosgo commented 8 years ago

你这是用数字做子域名了?

kwxiaozhu commented 8 years ago

不是,自定义单个字母做的子域名

dosgo commented 8 years ago

看你启动命令。、

kwxiaozhu commented 8 years ago

./ngrokc -SER[Shost:n.mydomain.pw,Sport:4443] -AddTun[Type:tcp,Lhost:10.0.1.2,Lport:7070] -AddTun[Type:http,Lhost:10.0.1.99,Lport:80,Sdname:z]

dosgo commented 8 years ago

那你访问的域名应该是z.mydomain.pw啊。。跟8081有关系嘛?

kwxiaozhu commented 8 years ago

/root/ngrok/bin/ngrokd -tlsKey=/root/ngrok/server.key -tlsCrt=/root/ngrok/server.crt -domain="n.mydomain.pw" -httpAddr="127.0.0.1:8081" -httpsAddr="127.0.0.1:8082" -log none 服务器端启动命令,为了少暴漏端口,8081和8082监听127.0.0.1,然后使用nginx反代n.mydomain.pw和*.n.mydomain.pw到本地的8081和8082端口。

dosgo commented 8 years ago

Tunnel :8081 not found是ngrok服务器返回的把。。问题是。。8081对程序来说隐形的。。8081这东西怎么感觉你的nginx配置有问题

kwxiaozhu commented 8 years ago

server { listen 80; server_name n.mydomain.pw .n.mydomain.pw; access_log off; location / { proxy_pass_header Server; proxy_set_header Host $http_host:8081; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_redirect off; proxy_pass http://127.0.0.1:8081/; } } server { listen 443; server_name n.mydomain.pw .n.mydomain.pw; ssl on; ssl_certificate /etc/nginx/mydomain.pw.crt; ssl_certificate_key /etc/nginx/mydomain.pw.key; ssl_session_timeout 5m; location / { proxy_pass_header Server; proxy_set_header Host $http_host:8082; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_redirect off; proxy_pass http://127.0.0.1:8082/; } }

正常启动的情况下是可以正常访问http的,但是当断线重连后端口就不对了,直接返回的是80端口,但是按ngrokd配置应该返回8081才对的

kwxiaozhu commented 8 years ago

我直接监听0.0.0.0:8081和0.0.0.0:8082,不使用nginx反代,断线重连后又重现这个问题了,说明和nginx的配置无关。重连后返回的是80端口,而80端口是无法访问的

dosgo commented 8 years ago

url是?

kwxiaozhu commented 8 years ago

重连后返回的是这个URL http://z.n.mydomain.pw ,刚启动时返回的是这个URL http://z.n.mydomain.pw:8081 明显后面8081才是能访问的 强制访问8081返回通道不存在,说明通道没有建立

dosgo commented 8 years ago

如果要用8081才能访问。。说明你的nginx反代没起作用。。这个返回是服务器给我的。。你把你的nginx关闭。。单独ngrokd。。再测试下是否正常。

kwxiaozhu commented 8 years ago

现在是重连后用8081也访问不了,返回通道不存在,说明通道没有建立。

dosgo commented 8 years ago

是1.32?60ms后看的?

kwxiaozhu commented 8 years ago

是的,等待重新连接上后看的,同时建立的还有一个tcp通道,重连后tcp通道是正常的,http通道不行

dosgo commented 8 years ago

我这边一切正常啊

dosgo commented 8 years ago

我用下你服务器测试

dosgo commented 8 years ago

我连不上你服务器

dosgo commented 8 years ago

好了,确实有bug。。你试试把。。这个你发的带有自己服务器地址的信息,删除把。。

dosgo commented 8 years ago

已经更新到1.33了

kwxiaozhu commented 8 years ago

非常感谢,我去试试!

kwxiaozhu commented 8 years ago

已经可以了,谢谢!