'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
+6 -6
View File
@@ -2,7 +2,7 @@ package broker
import ( import (
"crypto/tls" "crypto/tls"
"fhmq/lib/message" "hmq/lib/message"
"net" "net"
"net/http" "net/http"
"sync/atomic" "sync/atomic"
@@ -15,7 +15,7 @@ import (
type Broker struct { type Broker struct {
id string id string
cid unit64 cid uint64
config *Config config *Config
tlsConfig *tls.Config tlsConfig *tls.Config
clients cMap clients cMap
@@ -41,7 +41,7 @@ func NewBroker(config *Config) *Broker {
tlsconfig, err := NewTLSConfig(b.config.TlsInfo) tlsconfig, err := NewTLSConfig(b.config.TlsInfo)
if err != nil { if err != nil {
log.Error("new tlsConfig error: ", err) log.Error("new tlsConfig error: ", err)
return nil, err return nil
} }
b.tlsConfig = tlsconfig b.tlsConfig = tlsconfig
} }
@@ -64,7 +64,7 @@ func (b *Broker) Start() {
} }
func (b *Broker) StartWebsocketListening() { func (b *Broker) StartWebsocketListening() {
path := "/" + b.config.WsPath path := b.config.WsPath
hp := ":" + b.config.WsPort hp := ":" + b.config.WsPort
log.Info("Start Webscoker Listening on ", hp, path) log.Info("Start Webscoker Listening on ", hp, path)
http.Handle(path, websocket.Handler(b.wsHandler)) http.Handle(path, websocket.Handler(b.wsHandler))
@@ -77,7 +77,7 @@ func (b *Broker) StartWebsocketListening() {
func (b *Broker) wsHandler(ws *websocket.Conn) { func (b *Broker) wsHandler(ws *websocket.Conn) {
atomic.AddUint64(&b.cid, 1) atomic.AddUint64(&b.cid, 1)
go b.handleConnection(CLIENT, conn, b.cid) go b.handleConnection(CLIENT, ws, b.cid)
} }
func (b *Broker) StartTLSListening() { 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 //process connect packet
buf, err := ReadPacket(conn) buf, err := ReadPacket(conn)
if err != nil { if err != nil {
+1 -1
View File
@@ -2,7 +2,7 @@ package broker
import ( import (
"errors" "errors"
"fhmq/lib/message" "hmq/lib/message"
"net" "net"
"strings" "strings"
"sync" "sync"
+1 -2
View File
@@ -48,8 +48,7 @@ func LoadConfig() (*Config, error) {
log.Error("Read config file error: ", err) log.Error("Read config file error: ", err)
return nil, err return nil, err
} }
// log.Info(string(content))
log.Info(string(content))
var config Config var config Config
err = json.Unmarshal(content, &config) err = json.Unmarshal(content, &config)
+1 -1
View File
@@ -1,8 +1,8 @@
package broker package broker
import ( import (
"fhmq/lib/message"
"fmt" "fmt"
"hmq/lib/message"
"time" "time"
simplejson "github.com/bitly/go-simplejson" simplejson "github.com/bitly/go-simplejson"
+1 -1
View File
@@ -2,7 +2,7 @@ package broker
import ( import (
"errors" "errors"
"fhmq/lib/message" "hmq/lib/message"
"io" "io"
"net" "net"
+1 -1
View File
@@ -1,7 +1,7 @@
package main package main
import ( import (
"fhmq/broker" "hmq/broker"
"os" "os"
"os/signal" "os/signal"