Springboot+Netty搭建TCP客户端-多客户端

2023-05-16

之前搭建了一个Springboot+Netty服务端的应用,既然有服务端,自然也有客户端的应用,现在搭建一个Springboot+Netty客户端的应用Demo程序,多客户端方式,使用服务端和客户端进行联调测试,也可以用tcp的小工具来测试(中文可能乱码)

SpringBoot+Netty实现TCP服务端客户端的源码Demo

新建Springboot的maven项目,pom.xml文件导入依赖包

<?xml version="1.0"?>
<project
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
	xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<modelVersion>4.0.0</modelVersion>

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.0.5.RELEASE</version>
		<relativePath />
	</parent>

	<groupId>boot.base.tcp.client</groupId>
	<artifactId>boot-example-base-tcp-client-2.0.5</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>boot-example-base-tcp-client-2.0.5</name>
	<url>http://maven.apache.org</url>
	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>io.netty</groupId>
			<artifactId>netty-all</artifactId>
		</dependency>
		<dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-swagger2</artifactId>
			<version>2.9.2</version>
		</dependency>
		<dependency>
			<groupId>com.github.xiaoymin</groupId>
			<artifactId>swagger-bootstrap-ui</artifactId>
			<version>1.9.2</version>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<!-- 打包成一个可执行jar -->
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<executions>
					<execution>
						<goals>
							<goal>repackage</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project>

Springboot启动类,启动一个Netty的客户端

package boot.example.tcp.client;

import boot.example.tcp.client.netty.BootNettyClientThread;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

/**
 * 蚂蚁舞
 */
@SpringBootApplication
@EnableAsync
@EnableScheduling
public class BootNettyClientApplication implements CommandLineRunner{
    public static void main( String[] args ) {
		SpringApplication app = new SpringApplication(BootNettyClientApplication.class);
		app.run(args);

        System.out.println( "Hello World!" );
    }

    @Async
	@Override
	public void run(String... args) throws Exception {
		/**
		 * 使用异步注解方式启动netty客户端服务
		 */
		int port = 6655;
		String address = "127.0.0.1";
		int count = 10; // 模拟多个客户端
		for(int i = 0; i < count; i++) {
			BootNettyClientThread thread = new BootNettyClientThread(port, address);
			thread.start();
		}

	}
}

Netty的client类

package boot.example.tcp.client.netty;


import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;

/**
 * 
 * netty 客户端
 * 蚂蚁舞
 */
public class BootNettyClient {

	public void connect(int port, String host) throws Exception{
		
		/**
		 * 客户端的NIO线程组
		 * 
		 */
        EventLoopGroup group = new NioEventLoopGroup();
        
        try {
        	/**
        	 * Bootstrap 是一个启动NIO服务的辅助启动类 客户端的
        	 */
        	Bootstrap bootstrap = new Bootstrap();
        	bootstrap = bootstrap.group(group);
        	bootstrap = bootstrap.channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true);
        	/**
        	 * 设置 I/O处理类,主要用于网络I/O事件,记录日志,编码、解码消息
        	 */
        	bootstrap = bootstrap.handler(new BootNettyChannelInitializer<SocketChannel>());
        	/**
        	 * 连接服务端
        	 */
			ChannelFuture future = bootstrap.connect(host, port).sync();
			if(future.isSuccess()) {
				Channel channel = future.channel();
				String id = future.channel().id().toString();
				BootNettyClientChannel bootNettyClientChannel = new BootNettyClientChannel();
				bootNettyClientChannel.setChannel(channel);
				bootNettyClientChannel.setCode("clientId:"+id);
				BootNettyClientChannelCache.save("clientId:"+id, bootNettyClientChannel);
				System.out.println("netty client start success="+id);
				/**
				 * 等待连接端口关闭
				 */
				future.channel().closeFuture().sync();
			}
		} finally {
			/**
			 * 退出,释放资源
			 */
			group.shutdownGracefully().sync();
		}
        
	}
	

}

通道初始化

package boot.example.tcp.client.netty;


import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import io.netty.util.CharsetUtil;

/**
 * 通道初始化
 * 蚂蚁舞
 */
@ChannelHandler.Sharable
public class BootNettyChannelInitializer<SocketChannel> extends ChannelInitializer<Channel> {

	@Override
	protected void initChannel(Channel ch) throws Exception {

        ch.pipeline().addLast("encoder", new StringEncoder(CharsetUtil.UTF_8));
        ch.pipeline().addLast("decoder", new StringDecoder(CharsetUtil.UTF_8));
        /**
         * 自定义ChannelInboundHandlerAdapter
         */
        ch.pipeline().addLast(new BootNettyChannelInboundHandlerAdapter());
		
	}

}

客户端I/O数据读写处理类

package boot.example.tcp.client.netty;

import java.io.IOException;
import java.net.InetSocketAddress;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

/**
 * 
 * I/O数据读写处理类
 * 蚂蚁舞
 */
@ChannelHandler.Sharable
public class BootNettyChannelInboundHandlerAdapter extends ChannelInboundHandlerAdapter{
	
    /**
     * 从服务端收到新的数据时,这个方法会在收到消息时被调用
     */
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception, IOException {
        if(msg == null){
            return;
        }
    	System.out.println("channelRead:read msg:"+msg.toString());
        BootNettyClientChannel bootNettyClientChannel = BootNettyClientChannelCache.get("clientId:"+ctx.channel().id().toString());
        if(bootNettyClientChannel != null){
            System.out.println("to do");
            bootNettyClientChannel.setLast_data(msg.toString());
        }

        //回应服务端
        //ctx.write("I got server message thanks server!");
    }

    /**
     * 从服务端收到新的数据、读取完成时调用
     */
    @Override
    public void channelReadComplete(ChannelHandlerContext ctx) throws IOException {
    	System.out.println("channelReadComplete");
    	ctx.flush();
    }

    /**
     * 当出现 Throwable 对象才会被调用,即当 Netty 由于 IO 错误或者处理器在处理事件时抛出的异常时
     */
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws IOException {
    	System.out.println("exceptionCaught");
        cause.printStackTrace();
        ctx.close();//抛出异常,断开与客户端的连接
    }

    /**
     * 客户端与服务端第一次建立连接时 执行
     */
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception, IOException {
        super.channelActive(ctx);
        InetSocketAddress inSocket = (InetSocketAddress) ctx.channel().remoteAddress();
        String clientIp = inSocket.getAddress().getHostAddress();
        System.out.println(clientIp);
    }

    /**
     * 客户端与服务端 断连时 执行
     */
    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception, IOException {
        super.channelInactive(ctx);
        InetSocketAddress inSocket = (InetSocketAddress) ctx.channel().remoteAddress();
        String clientIp = inSocket.getAddress().getHostAddress();
        ctx.close(); //断开连接时,必须关闭,否则造成资源浪费
        System.out.println("channelInactive:"+clientIp);
    }
    

    
}

建立channel保存多客户端BootNettyClientChannel

package boot.example.tcp.client.netty;

import io.netty.channel.Channel;

/**
 * 	蚂蚁舞
 */
public class BootNettyClientChannel {

	//	连接客户端唯一的code
	private String code;

	//	客户端最新发送的消息内容
	private String last_data;

	private transient volatile Channel channel;

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public Channel getChannel() {
		return channel;
	}

	public void setChannel(Channel channel) {
		this.channel = channel;
	}

	public String getLast_data() {
		return last_data;
	}

	public void setLast_data(String last_data) {
		this.last_data = last_data;
	}
}

BootNettyClientChannelCache  
package boot.example.tcp.client.netty;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 *  蚂蚁舞
 */
public class BootNettyClientChannelCache {

    public static volatile Map<String, BootNettyClientChannel> channelMapCache = new ConcurrentHashMap<String, BootNettyClientChannel>();

    public static void add(String code, BootNettyClientChannel channel){
    	channelMapCache.put(code,channel);
    }

    public static BootNettyClientChannel get(String code){
        return channelMapCache.get(code);
    }

    public static void remove(String code){
    	channelMapCache.remove(code);
    }

    public static void save(String code, BootNettyClientChannel channel) {
        if(channelMapCache.get(code) == null) {
            add(code,channel);
        }
    }


}

netty的启动BootNettyClientThread

package boot.example.tcp.client.netty;


/**
 * 
 * netty 客户端
 * 蚂蚁舞
 */
public class BootNettyClientThread extends Thread {

	private final int port;

	private final String address;
	public BootNettyClientThread(int port, String address){
		this.port = port;
		this.address = address;
	}

	public void run() {
		try {
			new BootNettyClient().connect(port, address);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
}

心跳使用定时器BootNettyHeartTimer

package boot.example.tcp.client.netty;


import io.netty.buffer.Unpooled;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 *  蚂蚁舞
 */
@Service
public class BootNettyHeartTimer {

    //  使用定时器发送心跳
    @Scheduled(cron = "0/30 * * * * ?")
    public void heart_timer() {
        String back = "heart";
        if(BootNettyClientChannelCache.channelMapCache.size() > 0){
            for (Map.Entry<String, BootNettyClientChannel> entry : BootNettyClientChannelCache.channelMapCache.entrySet()) {
                BootNettyClientChannel bootNettyChannel = entry.getValue();
                if(bootNettyChannel != null && bootNettyChannel.getChannel().isOpen()){
                    bootNettyChannel.getChannel().writeAndFlush(Unpooled.buffer().writeBytes(back.getBytes()));
                }
            }
        }

    }

}

测试接口BootNettyClientController

package boot.example.tcp.client.controller;

import boot.example.tcp.client.netty.BootNettyClientChannel;
import boot.example.tcp.client.netty.BootNettyClientChannelCache;
import io.netty.buffer.Unpooled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 	蚂蚁舞
 */
@RestController
public class BootNettyClientController {

	@GetMapping("/list")
	public List<Map<String,String>> list() {
		List<Map<String,String>> list = new ArrayList<>();
		for (Map.Entry<String, BootNettyClientChannel> entry : BootNettyClientChannelCache.channelMapCache.entrySet()) {
			Map<String, String> map = new HashMap<String, String>();
			map.put("code", entry.getKey());
			//map.put("code", entry.getValue().getCode());
			map.put("last_data", entry.getValue().getLast_data());
			list.add(map);
		}
		return list;
	}

	@PostMapping("/reportAllClientDataToServer")
	public String reportAllClientDataToServer(@RequestParam(name="content", required = true) String content) {
		for (Map.Entry<String, BootNettyClientChannel> entry : BootNettyClientChannelCache.channelMapCache.entrySet()) {
			BootNettyClientChannel bootNettyChannel = entry.getValue();
			if(bootNettyChannel != null && bootNettyChannel.getChannel().isOpen()){
				bootNettyChannel.getChannel().writeAndFlush(Unpooled.buffer().writeBytes(content.getBytes()));
			}
		}
		return "ok";
	}

	@PostMapping("/reportClientDataToServer")
	public String downDataToClient(@RequestParam(name="code", required = true) String code, @RequestParam(name="content", required = true) String content) {
		BootNettyClientChannel bootNettyChannel = BootNettyClientChannelCache.get(code);
		if(bootNettyChannel != null && bootNettyChannel.getChannel().isOpen()){
			bootNettyChannel.getChannel().writeAndFlush(Unpooled.buffer().writeBytes(content.getBytes()));
			return "success";
		}
		return "fail";
	}



}

SwaggerConfig测试方便

package boot.example.tcp.client;

import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 *  蚂蚁舞
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
                .apis(RequestHandlerSelectors.any()).paths(PathSelectors.any())
                .paths(Predicates.not(PathSelectors.regex("/error.*")))
                .paths(PathSelectors.regex("/.*"))
                .build().apiInfo(apiInfo());
    }

    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("netty tcp 客户端demo")
                .description("netty tcp 客户端接口测试demo")
                .version("0.01")
                .build();
    }

    /**
     * http://localhost:8094/doc.html  地址和端口根据实际项目查看
     */


}

客户端demo代码的目录结构

├─boot-example-base-tcp-client-2.0.5
│  │  pom.xml
│  │  
│  ├─src
│  │  ├─main
│  │  │  ├─java
│  │  │  │  └─boot
│  │  │  │      └─example
│  │  │  │          └─tcp
│  │  │  │              └─client
│  │  │  │                  │  BootNettyClientApplication.java
│  │  │  │                  │  SwaggerConfig.java
│  │  │  │                  │  
│  │  │  │                  ├─controller
│  │  │  │                  │      BootNettyClientController.java
│  │  │  │                  │      
│  │  │  │                  └─netty
│  │  │  │                          BootNettyChannelInboundHandlerAdapter.java
│  │  │  │                          BootNettyChannelInitializer.java
│  │  │  │                          BootNettyClient.java
│  │  │  │                          BootNettyClientChannel.java
│  │  │  │                          BootNettyClientChannelCache.java
│  │  │  │                          BootNettyClientThread.java
│  │  │  │                          BootNettyHeartTimer.java
│  │  │  │                          
│  │  │  └─resources
│  │  │          application.properties
│  │  │          
│  │  └─test
│  │      └─java
│  │          └─boot
│  │              └─example
│  │                  └─tcp
│  │                      └─client
│  │                              BootNettyClientApplicationTest.java
│  │                              

基本demo客户端代码就完成了,要进行测试了。

我这里不使用tcp服务端工具测试,之前使用之前使用netty搭建的服务端进行交互测试

地址Springboot+Netty搭建TCP服务端_蚂蚁舞的博客-CSDN博客

测试步骤

先启动springBoot+Netty的服务端代码

2023-01-20 10:25:55.677  INFO 2664 --- [           main] s.d.s.w.s.ApiListingReferenceScanner     : Scanning for api listing references
2023-01-20 10:25:55.904  INFO 2664 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 6654 (http) with context path ''
2023-01-20 10:25:55.909  INFO 2664 --- [           main] b.e.t.server.BootNettyServerApplication  : Started BootNettyServerApplication in 6.752 seconds (JVM running for 7.598)
2023-01-20 10:25:55.915  INFO 2664 --- [           main] .s.a.AnnotationAsyncExecutionInterceptor : No task executor bean found for async processing: no bean of type TaskExecutor and no bean named 'taskExecutor' either
Hello World!
netty server start success!

可以浏览器web访问

http://localhost:6654/doc.html

再启动springBoot+Netty的客户端代码(多客户端啊,这里启动10个)

    	int port = 6655;
		String address = "127.0.0.1";
		int count = 10; // 模拟多个客户端
		for(int i = 0; i < count; i++) {
			BootNettyClientThread thread = new BootNettyClientThread(port, address);
			thread.start();
		}
2023-01-20 10:29:01.955  INFO 13120 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2023-01-20 10:29:01.966  INFO 13120 --- [           main] o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 2147483647
2023-01-20 10:29:01.967  INFO 13120 --- [           main] d.s.w.p.DocumentationPluginsBootstrapper : Context refreshed
2023-01-20 10:29:02.007  INFO 13120 --- [           main] d.s.w.p.DocumentationPluginsBootstrapper : Found 1 custom documentation plugin(s)
2023-01-20 10:29:02.053  INFO 13120 --- [           main] s.d.s.w.s.ApiListingReferenceScanner     : Scanning for api listing references
2023-01-20 10:29:02.205  INFO 13120 --- [           main] s.a.ScheduledAnnotationBeanPostProcessor : No TaskScheduler/ScheduledExecutorService bean found for scheduled processing
2023-01-20 10:29:02.257  INFO 13120 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8094 (http) with context path ''
2023-01-20 10:29:02.264  INFO 13120 --- [           main] b.e.t.client.BootNettyClientApplication  : Started BootNettyClientApplication in 6.258 seconds (JVM running for 7.18)
2023-01-20 10:29:02.270  INFO 13120 --- [           main] .s.a.AnnotationAsyncExecutionInterceptor : No task executor bean found for async processing: no bean of type TaskExecutor and no bean named 'taskExecutor' either
Hello World!
127.0.0.1
127.0.0.1
127.0.0.1
127.0.0.1
127.0.0.1
127.0.0.1
127.0.0.1
127.0.0.1
127.0.0.1
127.0.0.1
netty client start success=8f7ca2ce
netty client start success=987e23c5
netty client start success=dc272839
netty client start success=c74a53a9
netty client start success=cbf85db3
netty client start success=e6ff0519
netty client start success=bc0fc00f
netty client start success=29db84c8
netty client start success=6e20d3e6
netty client start success=30378f02

可以浏览客户端的web访问

 可以看到客户端启动了是个客户端,服务端也给客户端返回了服务端创建成功的code(实际是netty的通道id,唯一的拿来使用的)

可以看到服务端收到了来自客户端的心跳

 我选取一个客户端来测试客户端给服务端发送消息(含中文)


  {
    "code": "clientId:bc0fc00f",
    "last_data": "server:bd255b2d"
  }

 可以看到给服务端发送的数据是

蚂蚁舞mywhtw147258#$%^

服务端接收到的最新数据


  {
    "code": "server:bd255b2d",
    "report_last_data": "蚂蚁舞mywhtw147258#$%^"
  }

服务端控制台的打印日志

channelId=bd255b2ddata=蚂蚁舞mywhtw147258#$%^
channelReadComplete
channelId=bd255b2ddata=蚂蚁舞mywhtw147258#$%^
channelReadComplete

服务端给客户端发送消息的方式是一样的,以及服务端批量给客户端发送消息,还有多个客户端给服务端发送同样的消息,都是可以达到的。

基于springboot+netty的客户端和服务端就调通了,支持中文不乱码。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Springboot+Netty搭建TCP客户端-多客户端 的相关文章

随机推荐

  • Ubuntu安装sshd服务

    ubuntu安装ssh服务 一 安装shhd SSH分客户端openssh client和openssh server 如果你只是想登陆别的机器的SSH只需要安装openssh client xff08 ubuntu有默认安装 xff0c
  • Linux环境(六)--资源与限制

    资源与限制 运行在Linux系统上的程序是有资源限制的 这些也许是硬件引起的限制 例如内存 xff0c 也许由系统策略引起的限制 例如 xff0c 允许 的CPU时间 xff0c 或者是实现的限制 例如 xff0c 整数的尺寸或是文件名允许
  • 遇到了C/C++控制台程序无法输入中文的情况

    其实C C 43 43 控制台程序无法cin中文的情况并不是你使用了string xff0c string是能输入并保存中文的 xff1b 经过一番探究 xff0c 我发现主要的问题是文件的编码和控制台所处的代码页 xff08 控制台的编码
  • Jpg2Dcm中文乱码问题

    Jpg2Dcm中文乱码问题 最近老板提出了一个新的功能要求 xff0c 希望可以把图片转成dcm 在实现功能的问题中遇见了很多问题和掉过许多坑 于是在此记录下来 问题 xff1a 第一次在进行Jpg2Dcm时 xff0c 可以进行图片转dc
  • 神经网络的数学表达式,神经网络的数学理论

    什么是神经网络 神经网络可以指向两种 xff0c 一个是生物神经网络 xff0c 一个是人工神经网络 生物神经网络 xff1a 一般指生物的大脑神经元 xff0c 细胞 xff0c 触点等组成的网络 xff0c 用于产生生物的意识 xff0
  • python装饰器详解(四)---把参数传递给装饰器

    因为装饰器必须接收一个函数当做参数 所以 不可以直接把被装饰函数的参数传递给装饰器 装饰器就是一个普通的函数 xff0c 回顾 def my decorator func print 34 I am an ordinary function
  • Motion Deblurring图像运动去模糊代码

    http www di ens fr whyte Efficient Deblurring for Shaken and Partially Saturated Images http www di ens fr willow resear
  • maven执行install时报错 The packaging for this project did not assign a file to the build artifact

    问题描述 maven中执行plugins下面的install install时会报如下错误 span class token class name Failed span span class token keyword to span s
  • realsense相机两种获取相机内外参的方式

    https www it610 com article 1296417297711308800 htm 命令 xff1a rs sensor control 这个命令是一个exe文件 xff0c 可以去 C Program Files x8
  • wget设置代理

    1 在bash shell中设定代理 basrhc export http proxy 61 34 166 111 53A 167 3128 34 export ftp proxy 61 34 166 111 53A 167 3128 34
  • chown,chgrp,chmod,u+s,g+s,o+t

    chown user file directory change owner 将后面的目标文件或者目录的所有者替换成 user chgrp group file directory change group 将目标文件或者目录的所有组替换成
  • Segment Routing笔记(一)

    SR 理论 一 MPLS TE缺点 RSVP TE大部分都是为了FRR的目的不支持ECMP所有流量都需要在隧道里诞生了 战术型 TE xff0c 只在需要的时候使用 术语 TI LFA 与拓扑无关的无环路备份 xff0c 能保证备份路径的最
  • Springboot+Netty搭建UDP服务端

    UDP是一个无连接协议 xff0c 应用范围很大 xff0c 对于一些低功耗的设备可以使用UDP方式向云端推送消息信息 xff0c 也可以在推送消息时收到从云端原路返回的消息 xff0c 使用Netty 43 SpringBoot方式可以快
  • Springboot+Netty搭建UDP客户端

    使用Netty 43 SpringBoot方式可以快速地开发一套基于UDP协议的服务端程序 xff0c 同样的也可以开发客户端 xff0c 一般使用UDP都是使用原生的方式 xff0c 发送消息后就不管不问 xff0c 也就是不需要确定消息
  • Springboot+Netty搭建MQTT协议的服务端(基础Demo)

    Netty是业界最流行的nio框架之一 xff0c 结合springboot可以满足快速开发 MQTT xff08 Message Queuing Telemetry Transport xff0c 消息队列遥测传输协议 xff09 xff
  • SpringBoot+Shiro+Jwt+Vue+elementUI实现前后端分离单体系统Demo

    记录一下使用SpringBoot集成Shiro框架和Jwt框架实现前后端分离Web项目的过程 xff0c 后端使用SpringBoot整合Shiro 43 Jwt auth0 xff0c 前端使用vue 43 elementUI框架 xff
  • Centos系统安装RabbitMQ消息中间件

    记录一下在centos7 x下面安装RabbitMQ消息中间件 RabbitMQ是一个开源而且遵循 AMQP协议实现的基于 Erlang语言编写 xff0c 因此安装RabbitMQ之前是需要部署安装Erlang环境的 先安装Erlang
  • SpringBoot+RXTXcomm实现Java串口通信 读取串口数据以及发送数据

    记录一下使用SpringBoot 43 RXTXcomm实现Java串口通信 xff0c 使用Java语言开发串口 xff0c 对串口进行读写操作 RXTXcomm jar这个包支持的系统较多 xff0c 但是更新太慢 xff0c 在win
  • Springboot+Netty搭建TCP服务端

    Netty是业界最流行的nio框架之一 xff0c 它具有功能强大 性能优异 可定制性和可扩展性的优点 Netty的优点 xff1a 1 API使用简单 xff0c 开发入门门槛低 2 功能十分强大 xff0c 预置多种编码解码功能 xff
  • Springboot+Netty搭建TCP客户端-多客户端

    之前搭建了一个Springboot 43 Netty服务端的应用 xff0c 既然有服务端 xff0c 自然也有客户端的应用 xff0c 现在搭建一个Springboot 43 Netty客户端的应用Demo程序 xff0c 多客户端方式