Implementation of CoAP Server & Client in Go by @Kistler-Group
Switch branches/tags
Clone or download
Latest commit 8c46bd2 Dec 15, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples add Write for satisfy io.Writer interface in ResponseWriter Oct 12, 2018
.gitignore add feature multicast Jul 13, 2018
.travis.yml enable ipv6 on travis Jul 13, 2018
LICENSE add tcp, tcp-tls features + refactore of client, server Jun 1, 2018
README.md remove fork mention Oct 31, 2018
blockwise.go Fix responding to blockwise requests using Write Dec 4, 2018
blockwise_test.go Fix responding to blockwise requests using Write Dec 4, 2018
client.go fix of blockwise transfering - proper handle unexpected code, fix of … Nov 26, 2018
client_test.go fix for windows Oct 31, 2018
clientcommander.go add Write for satisfy io.Writer interface in ResponseWriter Oct 12, 2018
conn.go fix issues related to blockwise Oct 12, 2018
error.go fix of blockwise transfering - proper handle unexpected code, fix of … Nov 26, 2018
getresponsewriter.go fix of blockwise transfering - proper handle unexpected code, fix of … Nov 26, 2018
iotivity_test.go add Write for satisfy io.Writer interface in ResponseWriter Oct 12, 2018
message.go add Write for satisfy io.Writer interface in ResponseWriter Oct 12, 2018
message_test.go fix issues related to blockwise Oct 12, 2018
messagedgram.go fix issues related to blockwise Oct 12, 2018
messagetcp.go fix issues related to blockwise Oct 12, 2018
messagetcp_test.go add tcp, tcp-tls features + refactore of client, server Jun 1, 2018
multicastClient.go add DefaultPort and DefaultSecurityPort Oct 12, 2018
multicastClient_test.go fix issues related to blockwise Oct 12, 2018
networksession.go add Write for satisfy io.Writer interface in ResponseWriter Oct 12, 2018
request.go add ClientCommander as interface for users Oct 12, 2018
responsewriter.go Fix responding to blockwise requests using Write Dec 4, 2018
server.go fix of unlock not locked RWMutex Dec 4, 2018
server_test.go add DefaultPort and DefaultSecurityPort Oct 12, 2018
servermux.go Don't panic Dec 15, 2018
tokenhandler.go add ClientCommander as interface for users Oct 12, 2018
udp.go fix for windows Oct 31, 2018
utils.go add method OBSERVE to client Oct 12, 2018

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