Comments (3)
是的,每个packet都必须要有type。另外你没加type的话,server也不会崩溃,只是会断开conn而已。
from gotcp.
我换了 几台机器 都是这样 , 使用 nc 连接 ,或者使用端口扫描程序 扫描一下 就 崩溃。
(机器:linux (ubuntu 14.04) 和 debian (6) )
下面是 错误信息:
2014/10/29 00:03:23 readLoop panic: interface conversion: interface is nil, not int
panic: interface conversion: interface is nil, not int [recovered]
panic: interface conversion: interface is nil, not int
goroutine 49 [running]:
runtime.panic(0x519d20, 0xc20808e140)
/usr/local/go/src/pkg/runtime/panic.c:279 +0xf5
main.(_ConnDelegate).OnClose(0xc208042060, 0xc208078180)
/home/he/dev/go/src/gotcp/example/server.go:75 +0x6f
github.com/gansidui/gotcp.func·001()
/home/he/dev/go/src/github.com/gansidui/gotcp/conn.go:93 +0xa8
sync.(_Once).Do(0xc2080781b8, 0x7f3ac38fbf18)
/usr/local/go/src/pkg/sync/once.go:40 +0x9f
github.com/gansidui/gotcp.(_Conn).Close(0xc208078180)
/home/he/dev/go/src/github.com/gansidui/gotcp/conn.go:94 +0x51
github.com/gansidui/gotcp.func·002()
/home/he/dev/go/src/github.com/gansidui/gotcp/conn.go:204 +0xc6
runtime.panic(0x519d20, 0xc20808e100)
/usr/local/go/src/pkg/runtime/panic.c:248 +0x18d
main.(_ConnDelegate).OnIOError(0xc208042060, 0xc208078180, 0x7f3ac3a741b0, 0xc2080002b0)
/home/he/dev/go/src/gotcp/example/server.go:79 +0x5c
github.com/gansidui/gotcp.(_Conn).readLoop(0xc208078180)
/home/he/dev/go/src/github.com/gansidui/gotcp/conn.go:223 +0x268
created by github.com/gansidui/gotcp.(_Conn).Do
/home/he/dev/go/src/github.com/gansidui/gotcp/conn.go:195 +0x66
我对go网络编程没有经验 , 但是 最近一个项目着急 使用 一个tcpserver 接受 现场仪器数据。
就是服务器 向 客户端 发送一条指令 客户端回馈请求。
我写了一个 程序:https://github.com/xiaofeihe/modbustcpserver
老是运行一段时间就 崩溃。 我想 使用你的 GOTCP 来做我程序 的 网络 服务。 但是 没有 头部 的 type ,和长度 这两个 内容。 (现场仪器 不可能 加上这两个) 希望 你能指教 我 一下
from gotcp.
哥哥啊, 你是直接使用example/server.go吧,这只是一个例子,跟example/client.go配套的,你需要根据你的需求重写。 另外你上面的crash信息是由下面的代码导致的,你没有加入type,那么读取包长时就直接返回错误了,然后断开conn并回调OnIOError和OnClose, 此时的c.GetExtraData()应该是nil。
func (this *ConnDelegate) OnClose(c *gotcp.Conn) {
this.closeCount++
fmt.Printf("OnClose[***%v***]\n", c.GetExtraData().(int))
}
func (this *ConnDelegate) OnIOError(c *gotcp.Conn, err error) {
fmt.Printf("OnIOError[***%v***]:[%v]\n", c.GetExtraData().(int), err)
}
大概看了下你的程序 modbustcpserver, 运行一段时间之后崩溃,那是因为你没有分包导致的,如果你要使用TCP必须得自己分包,否则建议使用UDP。
你的代码的Handle函数中:
if lenght > 0 {
buf[lenght] = 0
}
这个语句是有问题的,你的crash可能就是这个导致的,length大于你的buffer大小就会crash。
感觉你是在用写C的方式写Go,字符串后面是不需要补'\0'的
from gotcp.
Related Issues (16)
- 有个疑问 HOT 1
- 异步服务有些问题. HOT 18
- 你这支持异步写数据么? HOT 5
- 建议以树形结构维护客户端,新增连接池,多协议,增加事件回调等 HOT 10
- 连接断掉,conn的HandleChannel里的packet未处理给丢弃了 HOT 3
- 请问如何优雅地使用gotcp框架做客户端? HOT 2
- 请问gotcp 框架的处理性能你有测试过吗? HOT 2
- ReadPacket后,未调用 OnMessage HOT 9
- conn.go中的asyncDo函数加*sync.WaitGroup的作用是什么?
- ReadPacket只能一次返回一个包呀. HOT 2
- 请教一个问题 HOT 1
- How to deal with half packet data? HOT 4
- 如何平滑重启或者停止server HOT 2
- waitGroup.Add(1) 不能放置于 goroutine 内部 HOT 1
- 关于waitgroup HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gotcp.