Implementation of CoAP Server & Client in Go by @Kistler-Group
Clone or download
Pull request Compare This branch is 14 commits ahead, 2 commits behind go-ocf:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
.gitignore
.travis.yml
LICENSE
README.md
blockwise.go
blockwise_test.go
client.go
client_test.go
clientcommander.go
conn.go
error.go
getresponsewriter.go
iotivity_test.go
message.go
message_test.go
messagedgram.go
messagetcp.go
messagetcp_test.go
multicastClient.go
multicastClient_test.go
networksession.go
request.go
responsewriter.go
server.go
server_test.go
servermux.go
tokenhandler.go
udp.go
utils.go

README.md

Build Status codecov Go Report

CoAP Client and Server for go

Features supported:

Not yet implemented:

  • CoAP over DTLS

Samples

Simple

Server UDP/TCP

	// Server
	// See /examples/simple/server/main.go
	func handleA(w coap.ResponseWriter, req *coap.Request) {
		log.Printf("Got message in handleA: path=%q: %#v from %v", req.Msg.Path(), req.Msg, req.Client.RemoteAddr())
		w.SetContentFormat(coap.TextPlain)
		log.Printf("Transmitting from A")
		if _, err := w.Write([]byte("hello world")); err != nil {
			log.Printf("Cannot send response: %v", err)
		}
	}

	func main() {
		mux := coap.NewServeMux()
		mux.Handle("/a", coap.HandlerFunc(handleA))

		log.Fatal(coap.ListenAndServe(":5688", "udp", mux))
		
		// for tcp
		// log.Fatal(coap.ListenAndServe(":5688", "tcp", mux))

		// fot tcp-tls
		// log.Fatal(coap.ListenAndServeTLS(":5688", CertPEMBlock, KeyPEMBlock, mux))
	}

Client

	// Client
	// See /examples/simpler/client/main.go
	func main() {
		co, err := coap.Dial("udp", "localhost:5688")
		
		// for tcp
		// co, err := coap.Dial("tcp", "localhost:5688")
		
		// for tcp-tls
		// co, err := coap.DialWithTLS("localhost:5688", &tls.Config{InsecureSkipVerify: true})

		if err != nil {
			log.Fatalf("Error dialing: %v", err)
		}

		resp, err := co.Get(path)

		if err != nil {
			log.Fatalf("Error sending request: %v", err)
		}

		log.Printf("Response payload: %v", resp.Payload())
	}

Observe / Notify

Server

Look to examples/observe/server/main.go

Client

Look to examples/observe/client/main.go

Multicast

Server

Look to examples/mcast/server/main.go

Client

Look to examples/mcast/client/main.go

License

MIT