duanpiangeng8958 2016-03-01 00:21
浏览 6

使用udpconnection和相关的有效负载信息创建映射

I am trying to create a map to save the key as the connected client and its payload information. this is my code. How do I go about it

The code allows the client to send payload information to the server

package main

import (
    "fmt"
    "log"
    "net"

    "github.com/dustin/go-coap"
)

func main() {
    //listening for inconming request
    log.Fatal(coap.ListenAndServe("udp", ":5683",
        //function to handle incoming Client COAP Request u...dpconnection from          Remote Host & the udp address of remote
        coap.FuncHandler(func(l *net.UDPConn, a *net.UDPAddr, m *coap.Message) *coap.Message {
            log.Printf("Got message path=%q: %#v from %v", m.Path(), m, a)

            var connection = make(map[net.UDPConn]coap.Message)

            fmt.Println(connection)

            // connection[l]= m.Payload[]
            fmt.Println("The connecion is ", connection)
            //var connection =make(map[]m) //check if the message of client is confirmed with the

            if m.IsConfirmable() {

                res := &coap.Message{
                    Type:      coap.Acknowledgement,
                    Code:      coap.Content,
                    MessageID: m.MessageID,
                    Token:     m.Token,
                    Payload:   []byte("Acknowledgement from Sever : hello to you!")}

                res.SetOption(coap.ContentFormat, coap.TextPlain)

                log.Printf("Got it client %s %T", m.Payload, &res)
                return res
            }

            return nil
        })))
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 linux驱动,linux应用,多线程
    • ¥20 我要一个分身加定位两个功能的安卓app
    • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
    • ¥15 IAR程序莫名变量多重定义
    • ¥15 (标签-UDP|关键词-client)
    • ¥15 关于库卡officelite无法与虚拟机通讯的问题
    • ¥15 目标检测项目无法读取视频
    • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
    • ¥100 求采集电商背景音乐的方法
    • ¥15 数学建模竞赛求指导帮助