Coder Social home page Coder Social logo

xiaolongdeng1990 / server_on_gnet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cclehui/server_on_gnet

0.0 0.0 0.0 95 KB

基于gnet网络框架编写的各种常见服务端server程序,可以用来学习和快速使用

License: MIT License

Go 100.00%

server_on_gnet's Introduction

server_on_gnet

基于gnet网络框架编写的各种常见服务端server程序,可以用来学习和快速使用

目前支持的协议类型

固定协议头大小,消息体不定长协议支持

./examples/tcp_fixed_head/tcp_fixed_head_server.go 中是具体的使用demo, 还包含了具体的测试client, 协议是完整的, 可以直接run起来试试

port := 8081
tcpServer := tcp_fixed_head.NewTCPFixHeadServer(port)
options := []gnet.Option{
	gnet.WithReusePort(true),
	gnet.WithMulticore(multicore),
	gnet.WithTCPKeepAlive(time.Second * 90),
}

err := tcp_fixed_head.Run(tcpServer, fmt.Sprintf("tcp://:%d", port), options...)

websocket server

./examples/websocket/websocket_server.go 中是具体的使用demo

websocket 协议是基于 https://github.com/gobwas/ws 这个库解析的,

gnet 如何 使用websocket库的? 核心代码是把 gnet.Conn封装一个 io.ReaderWriter接口出来, 具体代码在./websocket/upgrader.go中实现, gnet v2 connection 已兼容reader writer

port := 8081
addr := fmt.Sprintf(":%d", port)
tcpServer := websocket.NewEchoServer(addr)
options := []gnet.Option{
	gnet.WithReusePort(true),
		gnet.WithMulticore(true),
}
log.Fatal(gnet.Run(tcpServer, fmt.Sprintf("tcp://:%d", port), options...))

todo

  1. mqtt协议
  2. 连接管理
  3. pb协议
  4. thrift协议
  5. 长连接维持平台

server_on_gnet's People

Contributors

cclehui 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.