0

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
        })))
}
CrazyCrow
  • 4,125
  • 1
  • 28
  • 39
Ekaku509
  • 17
  • 6

0 Answers0