本文整理匯總了Golang中github.com/giskook/gotcp.Conn.GetExtraData方法的典型用法代碼示例。如果您正苦於以下問題:Golang Conn.GetExtraData方法的具體用法?Golang Conn.GetExtraData怎麽用?Golang Conn.GetExtraData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/giskook/gotcp.Conn
的用法示例。
在下文中一共展示了Conn.GetExtraData方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ReadPacket
func (this *MattressProtocol) ReadPacket(c *gotcp.Conn) (gotcp.Packet, error) {
smconn := c.GetExtraData().(*Conn)
buffer := smconn.GetBuffer()
conn := c.GetRawConn()
for {
data := make([]byte, 2048)
readLengh, err := conn.Read(data)
log.Printf("%X\n", data[0:readLengh])
if err != nil {
return nil, err
}
if readLengh == 0 {
return nil, gotcp.ErrConnClosing
} else {
buffer.Write(data[0:readLengh])
cmdid, pkglen := CheckProtocol(buffer)
// log.Printf("recv box cmd %d \n", cmdid)
pkgbyte := make([]byte, pkglen)
buffer.Read(pkgbyte)
switch cmdid {
case ReportStatus:
return ParseReportStatus(pkgbyte), nil
case HalfPack:
case Illegal:
}
}
}
}
示例2: ReadPacket
func (this *ShaProtocol) ReadPacket(c *gotcp.Conn) (gotcp.Packet, error) {
smconn := c.GetExtraData().(*Conn)
smconn.UpdateReadflag()
buffer := smconn.GetBuffer()
conn := c.GetRawConn()
for {
data := make([]byte, 2048)
readLengh, err := conn.Read(data)
if err != nil {
return nil, err
}
if readLengh == 0 {
return nil, gotcp.ErrConnClosing
} else {
buffer.Write(data[0:readLengh])
cmdid, pkglen := CheckProtocol(buffer)
pkgbyte := make([]byte, pkglen)
buffer.Read(pkgbyte)
switch cmdid {
case Login:
pkg := ParseLogin(pkgbyte, smconn)
return NewShaPacket(Login, pkg), nil
case HeartBeat:
pkg := ParseHeart(pkgbyte)
return NewShaPacket(HeartBeat, pkg), nil
case SendDeviceList:
pkg := ParseDeviceList(pkgbyte, smconn)
return NewShaPacket(SendDeviceList, pkg), nil
case OperateFeedback:
pkg := ParseFeedback(pkgbyte)
return NewShaPacket(OperateFeedback, pkg), nil
case Warn:
pkg := ParseWarn(pkgbyte)
return NewShaPacket(Warn, pkg), nil
case AddDelDevice:
pkg := ParseAddDelDevice(pkgbyte)
return NewShaPacket(AddDelDevice, pkg), nil
case SetDevicenameFeedback:
pkg := ParseFeedbackSetDevicename(pkgbyte)
return NewShaPacket(SetDevicenameFeedback, pkg), nil
case DelDeviceFeedback:
pkg := ParseFeedbackDelDevice(pkgbyte)
return NewShaPacket(DelDeviceFeedback, pkg), nil
case Illegal:
case HalfPack:
}
}
}
}
示例3: on_login
func on_login(c *gotcp.Conn, p *ShaPacket) {
conn := c.GetExtraData().(*Conn)
conn.Status = ConnSuccess
loginPkg := p.Packet.(*protocol.LoginPacket)
conn.IMEI = loginPkg.IMEI
conn.ID, _ = strconv.ParseUint(loginPkg.IMEI, 10, 64)
NewConns().SetID(conn.ID, conn.index)
c.AsyncWritePacket(p, time.Second)
time.AfterFunc(1*time.Second, func() {
set_interval_pkg := protocol.Parse_Set_Interval(loginPkg.Encryption, loginPkg.IMEI, loginPkg.SerialNumber)
c.AsyncWritePacket(set_interval_pkg, time.Second)
})
}
示例4: OnClose
func (this *TelnetCallback) OnClose(c *gotcp.Conn) {
fmt.Println("OnClose:", c.GetExtraData())
}
示例5: OnClose
func (this *Callback) OnClose(c *gotcp.Conn) {
conn := c.GetExtraData().(*Conn)
conn.Close()
}
示例6: OnClose
func (this *Callback) OnClose(c *gotcp.Conn) {
conn := c.GetExtraData().(*Conn)
conn.Close()
NewConns().Remove(conn.GetBedID())
NewBedHub().Remove(conn.GetBedID())
}
示例7: ReadPacket
func (this *BedProtocol) ReadPacket(c *gotcp.Conn) (gotcp.Packet, error) {
smconn := c.GetExtraData().(*Conn)
buffer := smconn.GetBuffer()
conn := c.GetRawConn()
for {
data := make([]byte, 2048)
readLengh, err := conn.Read(data)
log.Printf("recv %x", data[0:readLengh])
if err != nil {
return nil, err
}
if readLengh == 0 {
return nil, gotcp.ErrConnClosing
} else {
buffer.Write(data[0:readLengh])
cmdid, pkglen := CheckProtocol(buffer)
log.Println(cmdid)
log.Println(NewConns().Check(0))
if cmdid != Login && !NewConns().Check(smconn.GetBedID()) {
return nil, ErrNotLogin
}
smconn.UpdateReadflag()
pkgbyte := make([]byte, pkglen)
buffer.Read(pkgbyte)
switch cmdid {
case Login:
pkg := ParseLogin(pkgbyte, smconn)
return NewBedPacket(Login, pkg), nil
case HeartBeat:
pkg := ParseHeart(pkgbyte)
return NewBedPacket(HeartBeat, pkg), nil
case AppControlFeedback:
pkg := ParseAppControlFeedback(pkgbyte, smconn, AppControlFeedback)
return NewBedPacket(AppControlFeedback, pkg), nil
case HandleControlFeedback:
bedpkg := ParseHandleControlFeedback(pkgbyte)
smconn.SendToBed(bedpkg)
pkg := ParseAppControlFeedback(pkgbyte, smconn, HandleControlFeedback)
return NewBedPacket(HandleControlFeedback, pkg), nil
case AppPottyFeedback:
pkg := ParsePottyFeedback(pkgbyte, smconn, AppPottyFeedback)
return NewBedPacket(AppPottyFeedback, pkg), nil
case HandlePottyFeedback:
bedpkg := ParseHandlePottyFeedback(pkgbyte)
smconn.SendToBed(bedpkg)
pkg := ParsePottyFeedback(pkgbyte, smconn, HandlePottyFeedback)
return NewBedPacket(HandlePottyFeedback, pkg), nil
case AfterPotty:
bedpkg := ParseAfterPottyTobedFeedback(pkgbyte)
smconn.SendToBed(bedpkg)
pkg := ParseAfterPottyFeedback(pkgbyte, smconn)
return NewBedPacket(AfterPotty, pkg), nil
case AppBedReset:
pkg := ParseAppControlFeedback(pkgbyte, smconn, AppBedReset)
return NewBedPacket(AppBedReset, pkg), nil
case Illegal:
case HalfPack:
}
}
}
}
示例8: ReadPacket
func (this *ShaProtocol) ReadPacket(c *gotcp.Conn) (gotcp.Packet, error) {
smconn := c.GetExtraData().(*Conn)
var once sync.Once
once.Do(smconn.UpdateReadflag)
buffer := smconn.GetBuffer()
conn := c.GetRawConn()
for {
if smconn.ReadMore {
data := make([]byte, 2048)
readLengh, err := conn.Read(data)
log.Printf("<IN> %x\n", data[0:readLengh])
if err != nil {
return nil, err
}
if readLengh == 0 {
return nil, gotcp.ErrConnClosing
}
buffer.Write(data[0:readLengh])
}
cmdid, pkglen := protocol.CheckProtocol(buffer)
pkgbyte := make([]byte, pkglen)
buffer.Read(pkgbyte)
switch cmdid {
case protocol.Login:
pkg := protocol.ParseLogin(pkgbyte)
smconn.ReadMore = false
return NewShaPacket(protocol.Login, pkg), nil
case protocol.HeartBeat:
pkg := protocol.ParseHeart(pkgbyte, smconn.ID)
smconn.ReadMore = false
return NewShaPacket(protocol.HeartBeat, pkg), nil
case protocol.Add_Del_Device:
pkg := protocol.Parse_Add_Del_Device(pkgbyte, smconn.ID)
smconn.ReadMore = false
return NewShaPacket(protocol.Add_Del_Device, pkg), nil
case protocol.Notification:
pkg := protocol.Parse_Notification(pkgbyte, smconn.ID)
smconn.ReadMore = false
return NewShaPacket(protocol.Notification, pkg), nil
case protocol.Feedback_SetName:
pkg := protocol.Parse_Feedback_SetName(pkgbyte, smconn.ID)
smconn.ReadMore = false
return NewShaPacket(protocol.Feedback_SetName, pkg), nil
case protocol.Feedback_Del_Device:
pkg := protocol.Parse_Feedback_Del_Device(pkgbyte, smconn.ID)
smconn.ReadMore = false
return NewShaPacket(protocol.Feedback_Del_Device, pkg), nil
case protocol.Feedback_Query_Attr:
pkg := protocol.Parse_Feedback_Query_Attr(pkgbyte, smconn.ID)
smconn.ReadMore = false
return NewShaPacket(protocol.Feedback_Query_Attr, pkg), nil
case protocol.Feedback_Depolyment:
pkg := protocol.Parse_Feedback_Deployment(pkgbyte, smconn.ID)
smconn.ReadMore = false
return NewShaPacket(protocol.Feedback_Depolyment, pkg), nil
case protocol.Feedback_OnOff:
pkg := protocol.Parse_Feedback_Onoff(pkgbyte, smconn.ID)
smconn.ReadMore = false
return NewShaPacket(protocol.Feedback_OnOff, pkg), nil
case protocol.Feedback_Level_Control:
pkg := protocol.Parse_Feedback_Level_Control(pkgbyte, smconn.ID)
smconn.ReadMore = false
return NewShaPacket(protocol.Feedback_Level_Control, pkg), nil
case protocol.Illegal:
smconn.ReadMore = true
case protocol.HalfPack:
smconn.ReadMore = true
}
}
}