Skip to content

Commit

Permalink
wss for websocket
Browse files Browse the repository at this point in the history
  • Loading branch information
name5566 committed Feb 23, 2017
1 parent 17aea32 commit c82b2f9
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions network/ws_server.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package network

import (
"crypto/tls"
"github.com/gorilla/websocket"
"github.com/name5566/leaf/log"
"net"
Expand Down Expand Up @@ -101,6 +102,20 @@ func (server *WSServer) Start() {
log.Fatal("NewAgent must not be nil")
}

if server.CertFile != "" || server.KeyFile != "" {
config := &tls.Config{}
config.NextProtos = []string{"http/1.1"}

var err error
config.Certificates = make([]tls.Certificate, 1)
config.Certificates[0], err = tls.LoadX509KeyPair(server.CertFile, server.KeyFile)
if err != nil {
log.Fatal("%v", err)
}

ln = tls.NewListener(ln, config)
}

server.ln = ln
server.handler = &WSHandler{
maxConnNum: server.MaxConnNum,
Expand Down

0 comments on commit c82b2f9

Please sign in to comment.