基本信息
源码名称:Java实现内网穿透
源码大小:0.01M
文件格式:.zip
开发语言:Java
更新时间:2020-09-17
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
内网穿透、路由转发、代理Buffer实现循环缓冲提高效率,运行参数:本地端口 内网地址(域名) 内网端口 端口类型(固定1)


while (selectionKeyIterator.hasNext()) {
                            SelectionKey selectionKey = selectionKeyIterator.next();
                            SelectableChannel channel = selectionKey.channel();
                            HostConnectionAttachment channelAttach = (HostConnectionAttachment) selectionKey.attachment();
                            CircleBufferDelegate sendBufferDelegate = channelAttach.sendBufferDelegate;
                            CircleBufferDelegate recvBufferDelegate = channelAttach.recvBuffDelegate; if (selectionKey.isValid() && selectionKey.isReadable() && channel instanceof SocketChannel) {
                                SocketChannel socketChannel = (SocketChannel) channel; int read = -1; try { while ((read = socketChannel.read(sendBufferDelegate.getBuffer())) > 0) {
                                        SocketChannel otherChannel = channelAttach.socketChannel;
                                        sendBufferDelegate.flip(); while (sendBufferDelegate.hasRemaining()) { //                                            if (  i % 4 == 3) break;//模拟数据未读取完毕  int w = otherChannel.write(sendBufferDelegate.getBuffer()); if (w < 0) { throw new FCenterException("host write error");
                                            } if (w == 0) { break;
                                            }
                                        }
                                        sendBufferDelegate.back();
                                    } if (read == -1) {
                                        closeHostConnect(socketChannel, channelAttach);
                                    } else {
                                        sendBufferDelegate.flip(); if (sendBufferDelegate.hasRemaining())
                                            channelAttach.socketKey.interestOps(channelAttach.socketKey.interestOps() | SelectionKey.OP_WRITE);
                                        sendBufferDelegate.back();
                                    }
                                } catch (Exception e) {
                                    closeHostConnect(socketChannel, channelAttach);
                                    logger.error("host connection thread read error,cause:"  e.getMessage());
                                }
                            } else if (selectionKey.isValid() && selectionKey.isWritable() && channel instanceof SocketChannel) {
                                SocketChannel socketChannel = (SocketChannel) channel;
                                recvBufferDelegate.flip(); while (recvBufferDelegate.hasRemaining()) { //                                    if (  j % 4 == 3) break;//模拟数据未读取完毕  int w = socketChannel.write(recvBufferDelegate.getBuffer()); if (w < 0) { throw new FCenterException("host write error");
                                    }
                                } if (!recvBufferDelegate.hasRemaining())
                                    selectionKey.interestOps(selectionKey.interestOps() ^ SelectionKey.OP_WRITE);
                                recvBufferDelegate.back();
                            }
                            selectionKeyIterator.remove();
                        }