monkeyWie / proxyee

HTTP proxy server,support HTTPS&websocket.MITM impl,intercept and tamper HTTPS traffic.
MIT License
1.53k stars 573 forks source link

在proxyee里如何保持长连接 #79

Open liming1985 opened 4 years ago

liming1985 commented 4 years ago

app产品里有im的功能,打开app时会向im server发起一个建立连接的请求(get, application/octet-stream),一直保持连接不断,每隔5分钟接收一次服务端的心跳报文,这种在proxy里要如何做呢,指导一下呗,谢谢

liming1985 commented 4 years ago

经过proxyee后, 感觉和im server的心跳连接一直没建立上, app还一直发起建立连接的请求,日志里一直报错: 十二月 11, 2019 6:21:09 下午 io.netty.channel.AbstractChannelHandlerContext invokeExceptionCaught 警告: An exception 'java.lang.Exception: java.io.IOException: 你的主机中的软件中止了一个已建立的连接。' [enable DEBUG level for full stacktrace] was thrown by a user handler's exceptionCaught() method while handling the following exception: java.io.IOException: 你的主机中的软件中止了一个已建立的连接。 at sun.nio.ch.SocketDispatcher.read0(Native Method) at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43) at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223) at sun.nio.ch.IOUtil.read(IOUtil.java:192) at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:380) at io.netty.buffer.PooledUnsafeDirectByteBuf.setBytes(PooledUnsafeDirectByteBuf.java:288) at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1108) at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:345) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:148) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:647) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:582) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:499) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:461) at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.lang.Thread.run(Thread.java:748)

monkeyWie commented 4 years ago

为啥是通过http协议创建长连接啊

luyuanwan commented 4 years ago

自己写过一个HTTP代理的,带长链接的,不过是定制化的,不通用,原理就是保存了与远端服务器的链接对象,一直都用这个对象发送数据

luyuanwan commented 4 years ago

proxyee项目里可能不太好做长链接(也可能是自己太弱了,不会)

monkeyWie commented 4 years ago

@luyuanwan 实际上proxyee对目标服务器的连接是keep-alive的,也就是说已经是长连接实现的