~fnux/yggdrasil-go-coap

de44c52b3632edfc18239c41089939a74588cff4 — Jozef Kralik 2 years ago 3fa5306
add DefaultPort and DefaultSecurityPort
3 files changed, 15 insertions(+), 1 deletions(-)

M multicastClient.go
M server.go
M server_test.go
M multicastClient.go => multicastClient.go +1 -0
@@ 144,6 144,7 @@ func (mconn *MulticastClientConn) Publish(path string, responseHandler func(req 
		conn:  mconn,
	}
	err = mconn.client.multicastHandler.Add(req.Token(), func(w ResponseWriter, r *Request) {
		var err error
		switch r.Msg.Code() {
		case GET, POST, PUT, DELETE:
			//dont serve commands by multicast handler (filter own request)

M server.go => server.go +13 -1
@@ 6,6 6,7 @@ import (
	"crypto/tls"
	"net"
	"reflect"
	"strconv"
	"strings"
	"sync"
	"sync/atomic"


@@ 29,6 30,12 @@ const (
	defaultWriteBufferSize = 4096
)

//DefaultPort default unsecure port for COAP server
const DefaultPort = 5683

//DefaultSecurePort default secure port for COAP server
const DefaultSecurePort = 5684

//const tcpIdleTimeout time.Duration = 8 * time.Second

// Handler is implemented by any value that implements ServeCOAP.


@@ 207,7 214,12 @@ func (srv *Server) spawnWorker(w *Request) {
func (srv *Server) ListenAndServe() error {
	addr := srv.Addr
	if addr == "" {
		addr = ":domain"
		switch {
		case strings.Contains(srv.Net, "-tls"):
			addr = ":" + strconv.Itoa(DefaultSecurePort)
		default:
			addr = ":" + strconv.Itoa(DefaultPort)
		}
	}

	switch srv.Net {

M server_test.go => server_test.go +1 -0
@@ 406,6 406,7 @@ func testServingMCast(t *testing.T, lnet, laddr string, BlockWiseTransfer bool, 
		Handler: func(w ResponseWriter, r *Request) {
			resp := w.NewResponse(Content)
			resp.SetPayload(make([]byte, payloadLen))
			resp.SetOption(ContentFormat, TextPlain)
			err := w.WriteMsg(resp)
			if err != nil {
				t.Fatalf("cannot send response %v", err)