Coder Social home page Coder Social logo

gotcp's Introduction

gotcp

一个GO语言TCP网络库

服务器例子

  1. 组合嵌入gotcp.Session,制作自己的TCP网络会话

    例如:

    type Echo struct {
      gotcp.Session
    }
    
    func (this *Echo) OnRecv(data []byte, flag byte) {
      if this.IsVerified() == false {
        // ...(业务代码,略)...
        this.Verify()
      }
      // ...(业务代码,略)...
    }
    
    func (this *Echo) OnClose() {
      // ...(业务代码,略)...
    }
  2. 注册网络会话类,开启服务

    例如:

    s := &gotcp.Server{}
    s.RegisterSessType(Echo{})
    s.Start(":3000")

客户端例子

  1. 组合嵌入gotcp.Session,制作自己的TCP网络会话

    例如:

    type Echo struct {
      gotcp.Session
    }
    
    func (this *Echo) OnRecv(data []byte, flag byte) {
      if this.IsVerified() == false {
        // ...(业务代码,略)...
        this.Verify()
      }
      // ...(业务代码,略)...
    }
    
    func (this *Echo) OnClose() {
      // ...(业务代码,略)...
    }
  2. 连接服务器

    例如:

    echo := &Echo{}
    echo.Connect("localhost:3000", echo)

参考项目

参考了以下开源库:

基准测试

p1 p1

更多的测试

懒得在主页上写了,请参考: https://blog.csdn.net/u013272009/article/details/96873908

gotcp's People

Contributors

fananchong avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.