'webscoket'

This commit is contained in:
chowyu08
2017-08-26 14:25:38 +08:00
parent 0bbcaa582a
commit b1aee92142
6 changed files with 11 additions and 12 deletions

View File

@@ -2,7 +2,7 @@ package broker
import (
"crypto/tls"
"fhmq/lib/message"
"hmq/lib/message"
"net"
"net/http"
"sync/atomic"
@@ -15,7 +15,7 @@ import (
type Broker struct {
id string
cid unit64
cid uint64
config *Config
tlsConfig *tls.Config
clients cMap
@@ -41,7 +41,7 @@ func NewBroker(config *Config) *Broker {
tlsconfig, err := NewTLSConfig(b.config.TlsInfo)
if err != nil {
log.Error("new tlsConfig error: ", err)
return nil, err
return nil
}
b.tlsConfig = tlsconfig
}
@@ -64,7 +64,7 @@ func (b *Broker) Start() {
}
func (b *Broker) StartWebsocketListening() {
path := "/" + b.config.WsPath
path := b.config.WsPath
hp := ":" + b.config.WsPort
log.Info("Start Webscoker Listening on ", hp, path)
http.Handle(path, websocket.Handler(b.wsHandler))
@@ -77,7 +77,7 @@ func (b *Broker) StartWebsocketListening() {
func (b *Broker) wsHandler(ws *websocket.Conn) {
atomic.AddUint64(&b.cid, 1)
go b.handleConnection(CLIENT, conn, b.cid)
go b.handleConnection(CLIENT, ws, b.cid)
}
func (b *Broker) StartTLSListening() {
@@ -151,7 +151,7 @@ func (b *Broker) StartListening(typ int) {
}
}
func (b *Broker) handleConnection(typ int, conn net.Conn, idx int) {
func (b *Broker) handleConnection(typ int, conn net.Conn, idx uint64) {
//process connect packet
buf, err := ReadPacket(conn)
if err != nil {

View File

@@ -2,7 +2,7 @@ package broker
import (
"errors"
"fhmq/lib/message"
"hmq/lib/message"
"net"
"strings"
"sync"

View File

@@ -48,8 +48,7 @@ func LoadConfig() (*Config, error) {
log.Error("Read config file error: ", err)
return nil, err
}
log.Info(string(content))
// log.Info(string(content))
var config Config
err = json.Unmarshal(content, &config)

View File

@@ -1,8 +1,8 @@
package broker
import (
"fhmq/lib/message"
"fmt"
"hmq/lib/message"
"time"
simplejson "github.com/bitly/go-simplejson"

View File

@@ -2,7 +2,7 @@ package broker
import (
"errors"
"fhmq/lib/message"
"hmq/lib/message"
"io"
"net"

View File

@@ -1,7 +1,7 @@
package main
import (
"fhmq/broker"
"hmq/broker"
"os"
"os/signal"