Skip to content

wgcairui/midway-tcpserver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

midway-tcpserver

midway自定义TcpServer框架

npm i -S @cairui/midway-tcpserver

实现了自定义装饰器 *@TCPControll注册类

*@OnConnection() 连接处理

*@OnTCPMessage() 监听数据 默认监听data事件

*@OnTCPEmit() 触发本地事件 ,比如error

*@OnTCPWrite() 写入socket信息

示例

import { Provide, Inject } from "@midwayjs/decorator"
import { TCPControll, OnConnection, Context, OnDisConnection, OnTCPMessage, OnTCPEmit, OnTCPWrite } from "@cairui/midway-tcpserver"

@Provide()
@TCPControll()
export class TcpControll {

    @Inject()
    ctx!: Context

    @OnConnection()
    async connecting() {
        console.log(this.ctx.address());

    }

    @OnDisConnection()
    async disconnecting(reason: string) {
        console.log({ reason });

    }

    @OnTCPMessage("data")
    @OnTCPEmit("datass")
    @OnTCPWrite()
    async data(arg: any) {
        console.log({ arg });
        this.ctx.once("datass", a => {
            console.log({ a }, 'datasss');
        })
        return "ddddddddddddd"
    }

    @OnTCPMessage("datass")
    async test(arg: any) {


    }

}

midway文档 net文档

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published