TongxiJi / shadowsocks-java

shadowsocks server base on netty4 , tcp & udp full support,
MIT License
275 stars 77 forks source link

研究学习 #9

Open hegaoye opened 5 years ago

hegaoye commented 5 years ago

代码跑了下,手机测试无法使用,进去后直接进入

 protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
        boolean isUdp = ctx.channel().attr(SSCommon.IS_UDP).get();

        if (isUdp) {
            DatagramPacket udpRaw = ((DatagramPacket) msg);
            if (udpRaw.content().readableBytes() < 4) { //no cipher, min size = 1 + 1 + 2 ,[1-byte type][variable-length host][2-byte port]
                return;
            }
            ctx.channel().attr(SSCommon.RemoteAddr).set(udpRaw.sender());
            ctx.fireChannelRead(udpRaw.content());
        } else {
            ctx.channel().attr(SSCommon.RemoteAddr).set((InetSocketAddress) ctx.channel().remoteAddress());
            ctx.channel().pipeline().remove(this);
            ctx.fireChannelRead(msg);
        }
    }

总是进入到else然后测试中就没有结果了,我们的网络可以直接访问google的结果不行了。。。

hegaoye commented 5 years ago

我用的是ssr的手机客户端连接,是否是udp和tcp协议本身的的差别呢?这个是udp的吗?tcp是否支持?

hegaoye commented 5 years ago

@TongxiJi 这个服务器的netty执行流程是什么可以否分享下,我想学习下这个源码,同时学习下netty

TongxiJi commented 5 years ago

netty流程在这两个 SSLocal.java
SSServer.java

hegaoye commented 5 years ago

这两个已经看了,但是不太理解中间的网络通讯过程,和网络建立了几个长连接,以及用于通讯的连接等等,如果可以画一个简单的图来了解释可能会帮助更多人来学习这个网络过程和网络通讯原理。๑乛◡乛๑

TongxiJi commented 5 years ago

@hegaoye 画不起来了, 建议看下tcp和udp的基础。。。。。