| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- package internal
- import (
- "github.com/gorilla/websocket"
- "one.com/nnet"
- )
- //
- type WsClient struct {
- *Hub
- addr string
- pos int //
- }
- func NewWsClient(cf *nnet.HubConfig, cb nnet.ISessionCallback, p nnet.IProtocol) *WsClient {
- return &WsClient{
- Hub: newHub(cf, cb, p),
- pos: 0,
- }
- }
- func (self *WsClient) Start() error {
- return nil
- }
- func (self *WsClient) NewConnection(addr string, id uint64) error {
- conn, _, err := websocket.DefaultDialer.Dial(addr, nil)
- if err != nil {
- return err
- }
- self.wg.Add(1)
- go func() {
- ses := newSession(NewWsConn(conn), self)
- ses.UpdateId(id)
- ses.Do()
- self.wg.Done()
- }()
- return nil
- }
- func (self *WsClient) DoJob(int) {
- }
- func (self *WsClient) Stop() error {
- close(self.chQuit)
- self.wg.Wait()
- return nil
- }
|