Coder Social home page Coder Social logo

gnet-examples's Introduction

gnet-examples

Examples of gnet

gnet-examples's People

Contributors

dgqypl avatar mircodz avatar panjf2000 avatar wathenjiang avatar whiteccinn avatar yonderchen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

gnet-examples's Issues

WebSocket examples

There is a problem parsing WS data when the current frame is split into multiple fragments!

升级gnet版本为v1.6.3 出现问题

win环境下
1.自定义解码器 如果async==true 会出现调用两次encode的情况

2021/12/21 16:34:47 receive , &{32769 240 13 [128 1 0 240 0 0 0 5 104 101 108 108 111]}, data:�� �   �hello
2021/12/21 16:34:47 receive , &{32769 240 13 [128 1 0 240 0 0 0 5 119 111 114 108 100]}, data:�� �   �world

liunx环境下

  1. gnet.WithTCPKeepAlive(time.Minute*5) 似乎无效 发送一次就断开连接
  2. 关闭服务器程序后依然占用端口 大概2分钟左右解除占用

无法编译运行 codec/server

错误为
go get github.com/panjf2000/gnet/pool/goroutine: module github.com/panjf2000/gnet@upgrade found (v1.6.3), but does not contain package github.com/panjf2000/gnet/pool/goroutine

使用的版本为 WSL ubuntu20.04

HTTP 请求 header 和 body 不在同一个包发送的问题

Actions I've taken before I'm here

  • I've thoroughly read the documentations on this issue but still have no clue.
  • I've searched the Github Issues but didn't find any duplicate issues that have been resolved.
  • I've searched the internet for this issue but didn't find anything helpful.

What happened?

在 http demo 程序里面, c.Next(-1) 并没有拉到整个请求信息,而是只读取了 header 信息, body 信息没有读取,这样导致在 buf = buf[headerOffset+bodyLen:] ,数组越界 panic,我再次 c.Next 也拉不到更多内容, 但是在下一次 OnTraffic 回调 ,会把剩余的 body 信息读出来。 另外问一下 c.Next(-1) 需要开发者处理 TCP 的拆包和粘包问题吗?

func (hs *httpServer) OnTraffic(c gnet.Conn) gnet.Action {
    hc := c.Context().(*httpCodec)
    buf, _ := c.Next(-1)

pipeline:
    headerOffset, err := hc.parser.Parse(buf)
    if err != nil {
        c.Write(errMsgBytes)
        return gnet.Close
    }
    hc.appendResponse()
    bodyLen := int(hc.parser.ContentLength())
    if bodyLen == -1 {
        bodyLen = 0
    }
    buf = buf[headerOffset+bodyLen:]
    if len(buf) > 0 {
        goto pipeline
    }

    c.Write(hc.buf)
    hc.buf = hc.buf[:0]
    return gnet.None
}

Major version of gnet

v2

Specific version of gnet

v2.2.7

Operating system

macOS

Relevant log output

image

image

Code snippets (optional)

No response

How to Reproduce

Steps to reproduce the behavior:

  1. 写个 demo 程序
  2. 发送 http 请求
  3. 在 OnTraffic 查看 c.Next(-1)

Does this issue reproduce with the latest release?

It can reproduce with the latest release

Example echo server bugged

Was trying out this system, but I found out a issue.
The "c.SendTo(returnData)" is bugged, as it somehow is getting nil, same for c.RemoteAddr(), if I access that in the go func(), it's gone or overwritten by something not able to be used.
It works if I remove the go func(){}(), but then it's performance goes down the drain.
Anybody able to figure out what I could do to make it properly work ?

[edit] Correction, without go func() it doesn't work either.
Should work, but somehow the connection is just, gone...

func (es *echoServer) OnInitComplete(srv gnet.Server) (action gnet.Action) {
	console(fmt.Sprintf("UDP Echo server is listening on %s (multi-cores: %t, loops: %d)", srv.Addr.String(), srv.Multicore, srv.NumEventLoop), 3)
	return
}

func (es *echoServer) React(frame []byte, c gnet.Conn) (out []byte, action gnet.Action) {
	// Echo asynchronously.
	data := append([]byte{}, frame...)
	connection := c.RemoteAddr()
	go func() {
		returnData, err1 := udpParseMessage(c, connection, data)
		if err1 != nil {
			console(fmt.Sprintf("[%s] UDP Request Error: %v", getCurrentFuncName(), err1.Error()), 1)
			return
		}
		err2 := c.SendTo(returnData)
		if err2 != nil {
			console(fmt.Sprintf("[%s] UDP SendTo: %v", getCurrentFuncName(), err2.Error()), 1)
			return
		}
	}()
	return
}

ws example upgrade阻塞

ws example 例子中,使用了gws库的upgrader,这个upgrader的upgrade是阻塞式的,也就是意味着,如果http升级请求,出现分包的情况,会卡住事件循环. server端的tempreader有些多余.

Http-parser have a bug

req.query = req.path[q+1 : i]

req.path = sdata[s:q]
req.query = req.path[q+1 : i]

this code in http-parser have a bug, provide this error :
==> panic: runtime error: slice bounds out of range [:30] with length 15

i know you know what is problem ;-)

The server only replied to the requests of some browser clients

I use this websocket example. The browser client sends it 100 times, but only replies a few times


  for (let i = 0 ;i < 100 ; i++){
            doSend(i)
        }
function doSend(message) {
        websocket.send(JSON.stringify( {"code":1006,"symbol":message+""}));
    }

The server only replied to some requests

Questions on low latency websocket server with 10K concurrent clients?

Hi, @panjf2000 I have few questions on the websocket server

  1. Isn't this https://github.com/gnet-io/gnet-examples/blob/v2/websocket/server/websocket.go#L70 a blocking call?

  2. I am trying to build a websocket push based server that broadcasts a stream of notifications coming from a message bus to all the connected websocket clients . The requirement I have is super low latency, meaning the server should be able to broadcast messages to atleast 10K clients connected concurrently under 5ms. so the Question I have here is do I need to shard the 10K clients, and then manage state for active and disconnected clients and then process clients by shard myself or gnet does sll of this for me? Do you have any other suggestion on how best to accomplish this?

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.