本文整理匯總了Golang中github.com/antongulenko/RTP/protocols.Server類的典型用法代碼示例。如果您正苦於以下問題:Golang Server類的具體用法?Golang Server怎麽用?Golang Server使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Server類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ConfigureHeartbeat
func (client *Client) ConfigureHeartbeat(receiver *protocols.Server, token int64, timeout time.Duration) error {
packet := ConfigureHeartbeatPacket{
Token: token,
TargetServer: receiver.LocalAddr().String(),
Timeout: timeout,
}
reply, err := client.SendRequest(codeConfigureHeartbeat, packet)
if err != nil {
return err
}
return client.CheckReply(reply)
}
示例2: RegisterServer
func RegisterServer(server *protocols.Server) (*LoadStats, error) {
if err := server.Protocol().CheckIncludesFragment(Protocol.Name()); err != nil {
return nil, err
}
stats := &LoadStats{
server: server,
Received: stats.NewStats("Received"),
Missed: stats.NewStats("Missed"),
}
err := server.RegisterHandlers(protocols.ServerHandlerMap{
codeLoad: stats.handleLoad,
})
if err != nil {
return nil, err
}
return stats, nil
}
示例3: startLoadClient
func startLoadClient() (port int) {
port = start_rtp_port
var server *protocols.Server
var stats *load.LoadStats
for {
var err error
server, err = protocols.NewServer(net.JoinHostPort(rtp_ip, strconv.Itoa(port)), load.MiniProtocol)
if err != nil {
log.Printf("Failed to start Load server on port %v: %v", port, err)
port += 2
continue
}
stats, err = load.RegisterServer(server)
if err != nil {
log.Printf("Failed to register Load server on port %v: %v", port, err)
port += 2
continue
}
if print_load_packets {
stats.Handler = func(packet *load.LoadPacket) {
packet.PrintReceived()
}
}
break
}
tasks.AddNamed("client", server)
go func() {
for err := range server.Errors() {
log.Println("Error receiving Load:", err)
}
}()
log.Printf("Listening on %v UDP port %v for Load\n", rtp_ip, port)
statistics = append(statistics, stats.Received)
statistics = append(statistics, stats.Missed)
return
}
示例4: RegisterServerHandler
func RegisterServerHandler(server *protocols.Server, handler HeartbeatServerHandler) error {
if err := server.Protocol().CheckIncludesFragment(Protocol.Name()); err != nil {
return err
}
return server.RegisterHandlers(protocols.ServerHandlerMap{
codeHeartbeat: func(packet *protocols.Packet) *protocols.Packet {
val := packet.Val
if beat, ok := val.(*HeartbeatPacket); ok {
handler.HeartbeatReceived(beat)
} else {
server.LogError(fmt.Errorf("Heartbeat received with wrong payload: (%T) %v", val, val))
}
return nil
},
})
}
示例5: printServerErrors
func printServerErrors(servername string, server *protocols.Server) {
for err := range server.Errors() {
log.Println(servername + " error: " + err.Error())
}
}
示例6: printErrors
func printErrors(server *protocols.Server) {
for err := range server.Errors() {
log.Println("Server error: " + err.Error())
}
}