ehang-io / nps

一款轻量级、高性能、功能强大的内网穿透代理服务器。支持tcp、udp、socks5、http等几乎所有流量转发,可用来访问内网网站、本地支付接口调试、ssh访问、远程桌面,内网dns解析、内网socks5代理等等……,并带有功能强大的web管理端。a lightweight, high-performance, powerful intranet penetration proxy server, with a powerful web management terminal.
https://ehang.io/nps/documents
GNU General Public License v3.0
30.81k stars 5.59k forks source link

如何设置心跳等节省客户端流量 #963

Open Layty opened 2 years ago

Layty commented 2 years ago

客户端用的是4G,怎么配置节省流量

peaceanddemocracy commented 2 years ago

可以考虑增加timeout,不过似乎这个设置没有生效

NetBarDJ commented 1 year ago

4G流量日消耗50M问题:使用rpcapd+wireshark的io统计分析,发现是npc/nps通道流量占比高,npc/nps之间,每5钞有一批类似保活报文的交互,此报文频繁,所以流量高; 修改C:\Users\Administrator\go\pkg\mod\ehang.io\nps-mux@v0.0.0-20200617154922-5dc86cc6082a下的mux.go,在270行左右注释掉 case muxPingFlag: //ping // logs.Error("275") // s.sendInfo(muxPingReturn, muxPing, pack.content) // windowBuff.Put(pack.content) continue 修改E:\nps\nps_source\nps\bridge下的bridge.go的typeDeal函数中添加tcp keepalive的处理: case common.WORK_MAIN: if isPub { c.Close() return } if tcp_keepalive_intval == 0 { tcp_keepalive_intval=beego.AppConfig.DefaultInt("tcp_keepalive_interval", 15) } logs.Info("tcp_keepalive_interval:%d",tcp_keepaliveintval) tcpConn, ok := c.Conn.(*net.TCPConn) if ok { // add tcp keep alive option for signal connection = tcpConn.SetKeepAlive(true) _ = tcpConn.SetKeepAlivePeriod(time.Duration(tcp_keepalive_intval) * time.Second) } 在文件上部需添加变量声明:var tcp_keepalive_intval int = 0

NetBarDJ commented 1 year ago

我自己改了代码,重新编译后用在了产品里,我也是4G场景,要省流量,之前的npc太费流量了