mirror of
https://gitee.com/wujiawei1207537021/wu-lazy-cloud-network.git
synced 2025-06-07 22:07:55 +08:00
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:
commit
fae329ea3e
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
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">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>netty-proxy</artifactId>
|
<artifactId>netty-proxy</artifactId>
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package com.luck.client;
|
package com.luck.client;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
|
||||||
|
|
||||||
public class ClientStart {
|
public class ClientStart {
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
@ -1,44 +1,32 @@
|
|||||||
package com.luck.client;
|
package com.luck.client;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.util.AttributeKey;
|
import io.netty.util.AttributeKey;
|
||||||
import io.netty.util.internal.StringUtil;
|
import io.netty.util.internal.StringUtil;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
public class Constant {
|
public class Constant {
|
||||||
/**
|
/** 代理服务channel */
|
||||||
* 绑定访客id
|
|
||||||
*/
|
|
||||||
public static final AttributeKey<String> VID = AttributeKey.newInstance("vid");
|
|
||||||
/**
|
|
||||||
* 代理服务channel
|
|
||||||
*/
|
|
||||||
public static Channel proxyChannel = null;
|
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<>();
|
public static Map<String, Channel> vpc = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
/**
|
/** 访客,真实服务channel */
|
||||||
* 访客,真实服务channel
|
|
||||||
*/
|
|
||||||
public static Map<String, Channel> vrc = new ConcurrentHashMap<>();
|
public static Map<String, Channel> vrc = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
/**
|
/** 真实服务端口 */
|
||||||
* 真实服务端口
|
|
||||||
*/
|
|
||||||
public static int realPort = 8080;
|
public static int realPort = 8080;
|
||||||
|
|
||||||
/**
|
/** 服务端口 */
|
||||||
* 服务端口
|
|
||||||
*/
|
|
||||||
public static int serverPort = 16001;
|
public static int serverPort = 16001;
|
||||||
|
|
||||||
/**
|
/** 服务IP */
|
||||||
* 服务IP
|
|
||||||
*/
|
|
||||||
public static String serverIp = "127.0.0.1";
|
public static String serverIp = "127.0.0.1";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.luck.client;
|
package com.luck.client;
|
||||||
|
|
||||||
import com.luck.msg.MyMsg;
|
import com.luck.msg.MyMsg;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
@ -1,27 +1,33 @@
|
|||||||
package com.luck.client;
|
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.MyMsg;
|
||||||
import com.luck.msg.MyMsgDecoder;
|
import com.luck.msg.MyMsgDecoder;
|
||||||
import com.luck.msg.MyMsgEncoder;
|
import com.luck.msg.MyMsgEncoder;
|
||||||
|
|
||||||
import io.netty.bootstrap.Bootstrap;
|
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.nio.NioEventLoopGroup;
|
||||||
import io.netty.channel.socket.SocketChannel;
|
import io.netty.channel.socket.SocketChannel;
|
||||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||||
import io.netty.handler.timeout.IdleStateHandler;
|
import io.netty.handler.timeout.IdleStateHandler;
|
||||||
import io.netty.util.internal.StringUtil;
|
import io.netty.util.internal.StringUtil;
|
||||||
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
public class ProxySocket {
|
public class ProxySocket {
|
||||||
/**
|
|
||||||
* 重连代理服务
|
|
||||||
*/
|
|
||||||
private static final ScheduledExecutorService reconnectExecutor = Executors.newSingleThreadScheduledExecutor();
|
|
||||||
private static EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
|
private static EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
|
||||||
|
|
||||||
|
/** 重连代理服务 */
|
||||||
|
private static final ScheduledExecutorService reconnectExecutor = Executors.newSingleThreadScheduledExecutor();
|
||||||
|
|
||||||
public static Channel connectProxyServer() throws Exception {
|
public static Channel connectProxyServer() throws Exception {
|
||||||
reconnectExecutor.scheduleAtFixedRate(() -> {
|
reconnectExecutor.scheduleAtFixedRate(() -> {
|
||||||
try {
|
try {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.luck.client;
|
package com.luck.client;
|
||||||
|
|
||||||
import com.luck.msg.MyMsg;
|
import com.luck.msg.MyMsg;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
package com.luck.client;
|
package com.luck.client;
|
||||||
|
|
||||||
import io.netty.bootstrap.Bootstrap;
|
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.nio.NioEventLoopGroup;
|
||||||
import io.netty.channel.socket.SocketChannel;
|
import io.netty.channel.socket.SocketChannel;
|
||||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
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">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>netty-proxy</artifactId>
|
<artifactId>netty-proxy</artifactId>
|
||||||
|
@ -4,34 +4,22 @@ import java.util.Arrays;
|
|||||||
|
|
||||||
public class MyMsg {
|
public class MyMsg {
|
||||||
|
|
||||||
/**
|
/** 心跳 */
|
||||||
* 心跳
|
|
||||||
*/
|
|
||||||
public static final byte TYPE_HEARTBEAT = 0X00;
|
public static final byte TYPE_HEARTBEAT = 0X00;
|
||||||
|
|
||||||
/**
|
/** 连接成功 */
|
||||||
* 连接成功
|
|
||||||
*/
|
|
||||||
public static final byte TYPE_CONNECT = 0X01;
|
public static final byte TYPE_CONNECT = 0X01;
|
||||||
|
|
||||||
/**
|
/** 数据传输 */
|
||||||
* 数据传输
|
|
||||||
*/
|
|
||||||
public static final byte TYPE_TRANSFER = 0X02;
|
public static final byte TYPE_TRANSFER = 0X02;
|
||||||
|
|
||||||
/**
|
/** 连接断开 */
|
||||||
* 连接断开
|
|
||||||
*/
|
|
||||||
public static final byte TYPE_DISCONNECT = 0X09;
|
public static final byte TYPE_DISCONNECT = 0X09;
|
||||||
|
|
||||||
/**
|
/** 数据类型 */
|
||||||
* 数据类型
|
|
||||||
*/
|
|
||||||
private byte type;
|
private byte type;
|
||||||
|
|
||||||
/**
|
/** 消息传输数据 */
|
||||||
* 消息传输数据
|
|
||||||
*/
|
|
||||||
private byte[] data;
|
private byte[] data;
|
||||||
|
|
||||||
public byte getType() {
|
public byte getType() {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
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">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>netty-proxy</artifactId>
|
<artifactId>netty-proxy</artifactId>
|
||||||
|
@ -1,9 +1,15 @@
|
|||||||
|
|
||||||
package com.luck.server;
|
package com.luck.server;
|
||||||
|
|
||||||
import com.luck.msg.MyMsg;
|
import com.luck.msg.MyMsg;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
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.handler.timeout.IdleStateEvent;
|
||||||
import io.netty.util.internal.StringUtil;
|
import io.netty.util.internal.StringUtil;
|
||||||
|
|
||||||
|
@ -1,39 +1,29 @@
|
|||||||
package com.luck.server;
|
package com.luck.server;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.util.AttributeKey;
|
import io.netty.util.AttributeKey;
|
||||||
import io.netty.util.internal.StringUtil;
|
import io.netty.util.internal.StringUtil;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
public class Constant {
|
public class Constant {
|
||||||
/**
|
/** 客户端服务channel */
|
||||||
* 绑定channel_id
|
|
||||||
*/
|
|
||||||
public static final AttributeKey<String> VID = AttributeKey.newInstance("vid");
|
|
||||||
/**
|
|
||||||
* 客户端服务channel
|
|
||||||
*/
|
|
||||||
public static Channel clientChannel = null;
|
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<>();
|
public static Map<String, Channel> vcc = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
/**
|
/** 访客,访客服务channel */
|
||||||
* 访客,访客服务channel
|
|
||||||
*/
|
|
||||||
public static Map<String, Channel> vvc = new ConcurrentHashMap<>();
|
public static Map<String, Channel> vvc = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
/**
|
/** 服务代理端口 */
|
||||||
* 服务代理端口
|
|
||||||
*/
|
|
||||||
public static int visitorPort = 16002;
|
public static int visitorPort = 16002;
|
||||||
|
|
||||||
/**
|
/** 服务端口 */
|
||||||
* 服务端口
|
|
||||||
*/
|
|
||||||
public static int serverPort = 16001;
|
public static int serverPort = 16001;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,8 +2,13 @@ package com.luck.server;
|
|||||||
|
|
||||||
import com.luck.msg.MyMsgDecoder;
|
import com.luck.msg.MyMsgDecoder;
|
||||||
import com.luck.msg.MyMsgEncoder;
|
import com.luck.msg.MyMsgEncoder;
|
||||||
|
|
||||||
import io.netty.bootstrap.ServerBootstrap;
|
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.nio.NioEventLoopGroup;
|
||||||
import io.netty.channel.socket.SocketChannel;
|
import io.netty.channel.socket.SocketChannel;
|
||||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||||
@ -16,7 +21,6 @@ public class ServerSocket {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 启动服务端
|
* 启动服务端
|
||||||
*
|
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static void startServer() throws Exception {
|
public static void startServer() throws Exception {
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package com.luck.server;
|
package com.luck.server;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import com.luck.msg.MyMsg;
|
import com.luck.msg.MyMsg;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
@ -8,14 +11,6 @@ import io.netty.channel.ChannelOption;
|
|||||||
import io.netty.channel.SimpleChannelInboundHandler;
|
import io.netty.channel.SimpleChannelInboundHandler;
|
||||||
import io.netty.util.internal.StringUtil;
|
import io.netty.util.internal.StringUtil;
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* description: 访客处理程序
|
|
||||||
*
|
|
||||||
* @author 吴佳伟
|
|
||||||
* @date: 12.2.23 10:21
|
|
||||||
*/
|
|
||||||
public class VisitorHandler extends SimpleChannelInboundHandler<ByteBuf> {
|
public class VisitorHandler extends SimpleChannelInboundHandler<ByteBuf> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
2
pom.xml
2
pom.xml
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user