mirror of
https://gitee.com/wujiawei1207537021/wu-lazy-cloud-network.git
synced 2025-06-07 13:57:56 +08:00
init
This commit is contained in:
parent
fae329ea3e
commit
6cb17fbd58
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
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>
|
||||
|
@ -1,8 +1,5 @@
|
||||
package com.luck.client;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
|
||||
|
||||
public class ClientStart {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
@ -1,32 +1,44 @@
|
||||
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 {
|
||||
/** 代理服务channel */
|
||||
public static Channel proxyChannel = null;
|
||||
|
||||
/** 绑定访客id */
|
||||
/**
|
||||
* 绑定访客id
|
||||
*/
|
||||
public static final AttributeKey<String> VID = AttributeKey.newInstance("vid");
|
||||
|
||||
/** 访客,代理服务channel */
|
||||
/**
|
||||
* 代理服务channel
|
||||
*/
|
||||
public static Channel proxyChannel = null;
|
||||
/**
|
||||
* 访客,代理服务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";
|
||||
|
||||
/**
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.luck.client;
|
||||
|
||||
import com.luck.msg.MyMsg;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
@ -1,32 +1,26 @@
|
||||
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.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.*;
|
||||
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;
|
||||
|
||||
public class ProxySocket {
|
||||
private static EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
|
||||
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();
|
||||
|
||||
public static Channel connectProxyServer() throws Exception {
|
||||
reconnectExecutor.scheduleAtFixedRate(() -> {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.luck.client;
|
||||
|
||||
import com.luck.msg.MyMsg;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
@ -1,13 +1,7 @@
|
||||
package com.luck.client;
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
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.*;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
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>
|
||||
|
@ -4,22 +4,34 @@ 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() {
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
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>
|
||||
|
@ -1,15 +1,9 @@
|
||||
|
||||
package com.luck.server;
|
||||
|
||||
import com.luck.msg.MyMsg;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
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.channel.*;
|
||||
import io.netty.handler.timeout.IdleStateEvent;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
|
||||
|
@ -1,29 +1,39 @@
|
||||
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 */
|
||||
public static Channel clientChannel = null;
|
||||
|
||||
/** 绑定channel_id */
|
||||
/**
|
||||
* 绑定channel_id
|
||||
*/
|
||||
public static final AttributeKey<String> VID = AttributeKey.newInstance("vid");
|
||||
|
||||
/** 访客,客户服务channel */
|
||||
/**
|
||||
* 客户端服务channel
|
||||
*/
|
||||
public static Channel clientChannel = null;
|
||||
/**
|
||||
* 访客,客户服务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;
|
||||
|
||||
/**
|
||||
|
@ -2,13 +2,8 @@ package com.luck.server;
|
||||
|
||||
import com.luck.msg.MyMsgDecoder;
|
||||
import com.luck.msg.MyMsgEncoder;
|
||||
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
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.*;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
@ -21,6 +16,7 @@ public class ServerSocket {
|
||||
|
||||
/**
|
||||
* 启动服务端
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void startServer() throws Exception {
|
||||
|
@ -1,9 +1,6 @@
|
||||
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;
|
||||
@ -11,6 +8,8 @@ import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class VisitorHandler extends SimpleChannelInboundHandler<ByteBuf> {
|
||||
|
||||
@Override
|
||||
|
2
pom.xml
2
pom.xml
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user