本文整理匯總了Golang中github.com/giskook/gotcp.Conn.AsyncWritePacket方法的典型用法代碼示例。如果您正苦於以下問題:Golang Conn.AsyncWritePacket方法的具體用法?Golang Conn.AsyncWritePacket怎麽用?Golang Conn.AsyncWritePacket使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/giskook/gotcp.Conn
的用法示例。
在下文中一共展示了Conn.AsyncWritePacket方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: OnConnect
func (this *TelnetCallback) OnConnect(c *gotcp.Conn) bool {
addr := c.GetRawConn().RemoteAddr()
c.PutExtraData(addr)
fmt.Println("OnConnect:", addr)
c.AsyncWritePacket(NewTelnetPacket("unknow", []byte("Welcome to this Telnet Server")), 0)
return true
}
示例2: on_posup
func on_posup(c *gotcp.Conn, p *ShaPacket) {
log.Println("posupin")
posup_pkg := p.Packet.(*protocol.PosUpPacket)
if posup_pkg.WifiCount > 2 {
posup_pkg.LocationTime = time.Now().Format("060102150405")
sql := fmt.Sprintf("INSERT INTO t_posup_log(id, imme,location_time,datainfo,accesstype) VALUES ('%s',to_timestamp('%s','YYMMDDhh24miss'),'%s','%s')",
posup_pkg.IMEI, posup_pkg.LocationTime, posup_pkg.Wifi, 1)
log.Println("heihei", sql)
GetServer().Dbsrv.Insert(sql)
c.AsyncWritePacket(p, time.Second)
} else if posup_pkg.GPSFlag != "" {
c.AsyncWritePacket(p, time.Second)
log.Println("long", posup_pkg.Longitude)
if posup_pkg.Longitude != "" {
log.Println("-----tag 2")
posup_pkg.LocationTime = time.Now().Format("060102150405")
sql := fmt.Sprintf("INSERT INTO t_posup_log(imme,location_time,glat,glong) VALUES ('%s',to_timestamp('%s','YYMMDDhh24miss'),'%s','%s')",
posup_pkg.IMEI, posup_pkg.LocationTime, posup_pkg.Latitude, posup_pkg.Longitude)
log.Println(sql)
GetServer().Dbsrv.Insert(sql)
} else if posup_pkg.WifiCount > 2 {
log.Println("-----tag 3")
posup_pkg.LocationTime = time.Now().Format("060102150405")
sql := fmt.Sprintf("INSERT INTO t_posup_log(imme,location_time,datainfo,accesstype) VALUES ('%s',to_timestamp('%s','YYMMDDhh24miss'),'%s','%s')",
posup_pkg.IMEI, posup_pkg.LocationTime, posup_pkg.Wifi, 1)
log.Println("heihei", sql)
GetServer().Dbsrv.Insert(sql)
}
}
}
示例3: OnMessage
func (this *DasCallback) OnMessage(c *gotcp.Conn, p gotcp.Packet) bool {
// 0xBA command feedback 0xBB heartbeat 0xBC login
// 0xBA cmdtype(1-8) status(0/1) serialid
daspacket := p.(*DasPacket)
command := daspacket.GetData()
commandtype := daspacket.GetType()
fmt.Println("----onmessage ", command)
switch commandtype {
case 0xBA:
var result []byte
var cmdop byte
cmdop = command[0]*10 + command[1]
result = append(result, cmdop)
result = append(result, c.GetMac()...)
result = append(result, command[3:7]...)
result = append(result, command[2])
c.Send(c.GetTopic(), result)
fmt.Printf("-----recv should up the result%x \n", result)
case 0xBB:
c.SetTimeFlag(time.Now().Unix())
c.AsyncWritePacket(NewDasPacket(0xAB, command), time.Second)
case 0xBC:
c.SetID(getMac(command), c.GetIndex())
c.AsyncWritePacket(NewDasPacket(0xAC, command), time.Second)
default:
gktoolkit.Trace()
}
return true
}
示例4: 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)
})
}
示例5: on_warnup
func on_warnup(c *gotcp.Conn, p *ShaPacket) {
c.AsyncWritePacket(p, time.Second)
warnup_pkg := p.Packet.(*protocol.WarnUpPacket)
sql := fmt.Sprintf("INSERT INTO t_warnup_log(imme,warnstyle,warn_time) VALUES ('%s','%s',to_timestamp('%s','YYMMDDhh24miss'))",
warnup_pkg.IMEI, warnup_pkg.WarnStyle, time.Now().Format("060102150405"))
log.Println(sql)
GetServer().Dbsrv.Insert(sql)
time.AfterFunc(1*time.Second, func() {
locate_pkg := protocol.Parse_Locate(warnup_pkg.Encryption, warnup_pkg.IMEI, warnup_pkg.SerialNumber)
c.AsyncWritePacket(locate_pkg, time.Second)
})
}
示例6: OnMessage
func (this *Callback) OnMessage(c *gotcp.Conn, p gotcp.Packet) bool {
shaPacket := p.(*ShaPacket)
log.Println("onmessage packettype", shaPacket.Type)
switch shaPacket.Type {
case protocol.Login:
on_login(c, shaPacket)
case protocol.HeartBeat:
c.AsyncWritePacket(shaPacket, time.Second)
case protocol.PosUp:
on_posup(c, shaPacket)
case protocol.Echo:
c.AsyncWritePacket(shaPacket, time.Second)
case protocol.WarnUp:
on_warnup(c, shaPacket)
}
return true
}
示例7: OnMessage
func (this *Callback) OnMessage(c *gotcp.Conn, p gotcp.Packet) bool {
bedPacket := p.(*BedPacket)
switch bedPacket.Type {
case Login:
c.AsyncWritePacket(bedPacket, time.Second)
case HeartBeat:
c.AsyncWritePacket(bedPacket, time.Second)
case AppControlFeedback:
GetServer().GetProducer().Send(GetServer().GetTopic(), p.Serialize())
case HandleControlFeedback:
GetServer().GetProducer().Send(GetServer().GetTopic(), p.Serialize())
case AppPottyFeedback:
GetServer().GetProducer().Send(GetServer().GetTopic(), p.Serialize())
case HandlePottyFeedback:
GetServer().GetProducer().Send(GetServer().GetTopic(), p.Serialize())
case AfterPotty:
GetServer().GetProducer().Send(GetServer().GetTopic(), p.Serialize())
case AppBedReset:
GetServer().GetProducer().Send(GetServer().GetTopic(), p.Serialize())
}
return true
}
示例8: OnMessage
func (this *TelnetCallback) OnMessage(c *gotcp.Conn, p gotcp.Packet) bool {
packet := p.(*TelnetPacket)
command := packet.GetData()
commandType := packet.GetType()
switch commandType {
case "echo":
c.AsyncWritePacket(NewTelnetPacket("echo", command), 0)
case "login":
c.AsyncWritePacket(NewTelnetPacket("login", []byte(string(command)+" has login")), 0)
case "quit":
return false
default:
c.AsyncWritePacket(NewTelnetPacket("unknow", []byte("unknow command")), 0)
}
return true
}
示例9: OnMessage
func (this *Callback) OnMessage(c *gotcp.Conn, p gotcp.Packet) bool {
echoPacket := p.(*echo.EchoPacket)
fmt.Printf("OnMessage:[%v] [%v]\n", echoPacket.GetLength(), string(echoPacket.GetBody()))
c.AsyncWritePacket(echo.NewEchoPacket(echoPacket.Serialize(), true), time.Second)
return true
}