io-netty-tcp

io-netty封装

License

License

Categories

Categories

Net Netty Networking
GroupId

GroupId

com.github.yafeiwang1240
ArtifactId

ArtifactId

io-netty-tcp
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

io-netty-tcp
io-netty封装

Download io-netty-tcp

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.yafeiwang1240/io-netty-tcp/ -->
<dependency>
    <groupId>com.github.yafeiwang1240</groupId>
    <artifactId>io-netty-tcp</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.yafeiwang1240/io-netty-tcp/
implementation 'com.github.yafeiwang1240:io-netty-tcp:1.0.0'
// https://jarcasting.com/artifacts/com.github.yafeiwang1240/io-netty-tcp/
implementation ("com.github.yafeiwang1240:io-netty-tcp:1.0.0")
'com.github.yafeiwang1240:io-netty-tcp:jar:1.0.0'
<dependency org="com.github.yafeiwang1240" name="io-netty-tcp" rev="1.0.0">
  <artifact name="io-netty-tcp" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.yafeiwang1240', module='io-netty-tcp', version='1.0.0')
)
libraryDependencies += "com.github.yafeiwang1240" % "io-netty-tcp" % "1.0.0"
[com.github.yafeiwang1240/io-netty-tcp "1.0.0"]

Dependencies

compile (7)

Group / Artifact Type Version
org.slf4j : slf4j-api jar 1.7.25
io.netty : netty-all jar 4.1.32.Final
com.alibaba : fastjson jar 1.2.47
org.apache.curator : curator-recipes jar 2.12.0
com.typesafe : config jar 1.3.3
de.ruedigermoeller : fst jar 2.56
com.github.yafeiwang1240 : OBrien jar 1.0.3

test (1)

Group / Artifact Type Version
junit : junit jar 4.11

Project Modules

There are no modules declared in this project.

基于io-netty架构的通讯服务器

使用示例
package com.github.yafeiwang124.tcp;

import com.github.yafeiwang124.tcp.liaison.Liaison;
import com.github.yafeiwang124.tcp.network.handler.IRequestHandler;
import com.github.yafeiwang124.tcp.network.server.ServerInfo;
import com.github.yafeiwang124.tcp.network.server.impl.TcpServer;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args ) throws Exception {
        System.out.println( "Hello World!" );
        TcpServer tcpServer = new TcpServer();
        tcpServer.addHandler(new JobConfigHandler());
        TcpServerThread tcpServerThread = new TcpServerThread(tcpServer);
        new Thread(tcpServerThread).start();
        Liaison liaison = new Liaison("tcp", 1, 60000, () -> {
            List<ServerInfo> serverInfoList = new ArrayList<>();
            serverInfoList.add(new ServerInfo("127.0.0.1", 1240));
            return serverInfoList;
        });
        JobConfig config = new JobConfig();
        config.setId(10L);
        config.setMsg("hhhhhhhhhh");
        String str = liaison.ask(config);
        System.out.println(str);
        liaison.close();
    }

    public static class JobConfigHandler implements IRequestHandler<JobConfig, String> {

        @Override
        public Class<JobConfig> messageType() {
            return JobConfig.class;
        }

        @Override
        public String handle(JobConfig message) throws Exception {
            System.out.println(message.getMsg());
            return "01 01 我是02";
        }
    }

    public static class JobConfig implements Serializable {
        private Long id;
        private String msg;
        public JobConfig(){

        }

        public Long getId() {
            return id;
        }

        public void setId(Long id) {
            this.id = id;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }
    }

    public static class TcpServerThread implements Runnable {
        private TcpServer tcpServer;
        public TcpServerThread(TcpServer tcpServer) {
            this.tcpServer = tcpServer;
        }
        @Override
        public void run() {
            try {
                tcpServer.start();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
 

Versions

Version
1.0.0