Merge remote-tracking branch 'origin/master'

# Conflicts:
#	netty-proxy-client/pom.xml
#	netty-proxy-client/src/main/java/com/luck/client/ClientStart.java
#	netty-proxy-client/src/main/java/com/luck/client/Constant.java
#	netty-proxy-client/src/main/java/com/luck/client/ProxyHandler.java
#	netty-proxy-client/src/main/java/com/luck/client/ProxySocket.java
#	netty-proxy-client/src/main/java/com/luck/client/RealHandler.java
#	netty-proxy-client/src/main/java/com/luck/client/RealSocket.java
#	netty-proxy-client/src/main/java/com/luck/client/controller/ClientController.java
#	netty-proxy-common/pom.xml
#	netty-proxy-common/src/main/java/com/luck/msg/MyMsg.java
#	netty-proxy-common/src/main/java/com/luck/msg/MyMsgDecoder.java
#	netty-proxy-common/src/main/java/com/luck/msg/MyMsgEncoder.java
#	netty-proxy-server/pom.xml
#	netty-proxy-server/src/main/java/com/luck/server/ClientHandler.java
#	netty-proxy-server/src/main/java/com/luck/server/Constant.java
#	netty-proxy-server/src/main/java/com/luck/server/ServerSocket.java
#	netty-proxy-server/src/main/java/com/luck/server/VisitorHandler.java
#	netty-proxy-server/src/main/java/com/luck/server/VisitorSocket.java
#	netty-proxy-server/src/main/java/com/luck/server/controller/ServerController.java
#	pom.xml
This commit is contained in:
wujiawei 2023-02-12 10:34:07 +08:00
commit fae329ea3e
20 changed files with 831 additions and 843 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>netty-proxy</artifactId>

View File

@ -1,5 +1,8 @@
package com.luck.client;
import org.springframework.boot.SpringApplication;
public class ClientStart {
public static void main(String[] args) throws Exception {

View File

@ -1,44 +1,32 @@
package com.luck.client;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import io.netty.channel.Channel;
import io.netty.util.AttributeKey;
import io.netty.util.internal.StringUtil;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class Constant {
/**
* 绑定访客id
*/
public static final AttributeKey<String> VID = AttributeKey.newInstance("vid");
/**
* 代理服务channel
*/
/** 代理服务channel */
public static Channel proxyChannel = null;
/**
* 访客代理服务channel
*/
/** 绑定访客id */
public static final AttributeKey<String> VID = AttributeKey.newInstance("vid");
/** 访客代理服务channel */
public static Map<String, Channel> vpc = new ConcurrentHashMap<>();
/**
* 访客真实服务channel
*/
/** 访客真实服务channel */
public static Map<String, Channel> vrc = new ConcurrentHashMap<>();
/**
* 真实服务端口
*/
/** 真实服务端口 */
public static int realPort = 8080;
/**
* 服务端口
*/
/** 服务端口 */
public static int serverPort = 16001;
/**
* 服务IP
*/
/** 服务IP */
public static String serverIp = "127.0.0.1";
/**

View File

@ -1,6 +1,7 @@
package com.luck.client;
import com.luck.msg.MyMsg;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;

View File

@ -1,27 +1,33 @@
package com.luck.client;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import com.luck.msg.MyMsg;
import com.luck.msg.MyMsgDecoder;
import com.luck.msg.MyMsgEncoder;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.timeout.IdleStateHandler;
import io.netty.util.internal.StringUtil;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class ProxySocket {
/**
* 重连代理服务
*/
private static final ScheduledExecutorService reconnectExecutor = Executors.newSingleThreadScheduledExecutor();
private static EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
/** 重连代理服务 */
private static final ScheduledExecutorService reconnectExecutor = Executors.newSingleThreadScheduledExecutor();
public static Channel connectProxyServer() throws Exception {
reconnectExecutor.scheduleAtFixedRate(() -> {
try {

View File

@ -1,6 +1,7 @@
package com.luck.client;
import com.luck.msg.MyMsg;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;

View File

@ -1,7 +1,13 @@
package com.luck.client;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>netty-proxy</artifactId>

View File

@ -4,34 +4,22 @@ import java.util.Arrays;
public class MyMsg {
/**
* 心跳
*/
/** 心跳 */
public static final byte TYPE_HEARTBEAT = 0X00;
/**
* 连接成功
*/
/** 连接成功 */
public static final byte TYPE_CONNECT = 0X01;
/**
* 数据传输
*/
/** 数据传输 */
public static final byte TYPE_TRANSFER = 0X02;
/**
* 连接断开
*/
/** 连接断开 */
public static final byte TYPE_DISCONNECT = 0X09;
/**
* 数据类型
*/
/** 数据类型 */
private byte type;
/**
* 消息传输数据
*/
/** 消息传输数据 */
private byte[] data;
public byte getType() {

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>netty-proxy</artifactId>

View File

@ -1,9 +1,15 @@
package com.luck.server;
import com.luck.msg.MyMsg;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.*;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOption;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.timeout.IdleStateEvent;
import io.netty.util.internal.StringUtil;

View File

@ -1,39 +1,29 @@
package com.luck.server;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import io.netty.channel.Channel;
import io.netty.util.AttributeKey;
import io.netty.util.internal.StringUtil;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class Constant {
/**
* 绑定channel_id
*/
public static final AttributeKey<String> VID = AttributeKey.newInstance("vid");
/**
* 客户端服务channel
*/
/** 客户端服务channel */
public static Channel clientChannel = null;
/**
* 访客客户服务channel
*/
/** 绑定channel_id */
public static final AttributeKey<String> VID = AttributeKey.newInstance("vid");
/** 访客客户服务channel */
public static Map<String, Channel> vcc = new ConcurrentHashMap<>();
/**
* 访客访客服务channel
*/
/** 访客访客服务channel */
public static Map<String, Channel> vvc = new ConcurrentHashMap<>();
/**
* 服务代理端口
*/
/** 服务代理端口 */
public static int visitorPort = 16002;
/**
* 服务端口
*/
/** 服务端口 */
public static int serverPort = 16001;
/**

View File

@ -2,8 +2,13 @@ package com.luck.server;
import com.luck.msg.MyMsgDecoder;
import com.luck.msg.MyMsgEncoder;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.*;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
@ -16,7 +21,6 @@ public class ServerSocket {
/**
* 启动服务端
*
* @throws Exception
*/
public static void startServer() throws Exception {

View File

@ -1,6 +1,9 @@
package com.luck.server;
import java.util.UUID;
import com.luck.msg.MyMsg;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
@ -8,14 +11,6 @@ import io.netty.channel.ChannelOption;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.internal.StringUtil;
import java.util.UUID;
/**
* description: 访客处理程序
*
* @author 吴佳伟
* @date: 12.2.23 10:21
*/
public class VisitorHandler extends SimpleChannelInboundHandler<ByteBuf> {
@Override

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>