Examples of gnet
gnet-io / gnet-examples Goto Github PK
View Code? Open in Web Editor NEWExamples of gnet
License: MIT License
Examples of gnet
License: MIT License
There is a problem parsing WS data when the current frame is split into multiple fragments!
rt
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环境下
错误为
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 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
}
v2
v2.2.7
macOS
No response
Steps to reproduce the behavior:
It can reproduce with the latest release
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
}
How to close all connections and restart the gnet tcp server after a certain period of time?
please make a full example with push example,
it seems gnet lack of good documentation
使用的是 v1.0.1 版本, windows .
Options 里面的 TCPKeepAlive 设置了5秒好像没反应哦.
gnet借鉴了netty,但是并没有看到客户端booststrap代码,大部分都是作为服务端
great software. only need to do a simple reverse proxy example and it's complete
ws example 例子中,使用了gws库的upgrader,这个upgrader的upgrade是阻塞式的,也就是意味着,如果http升级请求,出现分包的情况,会卡住事件循环. server端的tempreader有些多余.
gnet-examples/examples/http/http.go
Line 160 in 4c982ee
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 ;-)
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
Hi, @panjf2000 I have few questions on the websocket server
Isn't this https://github.com/gnet-io/gnet-examples/blob/v2/websocket/server/websocket.go#L70 a blocking call?
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?
it's fantastic. hope to see a haproxy example. appreciate it
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.