func newClient(ws *websocket.Conn, h *hub, srv *wsServer) *wsClient { if ws == nil { log.Panicln("ws cannot be nil") } if srv == nil { log.Panicln("server cannot be nil") } maxID++ return &wsClient{ id: maxID, ws: ws, h: h, srv: srv, subs: make(map[string]string), inMsgChan: make(chan *wsMessage), outMsgChan: make(chan *wsMessage), doneChan: make(chan bool), socketID: sha1Sum(fmt.Sprintf("%s-%s-%d", ws.RemoteAddr().String(), ws.LocalAddr().String(), maxID)), } }
func NewCcusConn(ws *websocket.Conn, cc_in chan updateInfo) *ccusConn { log.Printf("ws[%s]:new connect %s", ws.RemoteAddr(), ws.LocalAddr()) ws.SetReadDeadline(time.Now().Add(pongWait)) ws.SetWriteDeadline(time.Now().Add(writeWait)) pc := &ccusConn{} pc.ws = ws pc.cc_in = cc_in go pc.receiver() return pc }
func NewConnection(ws *websocket.Conn) (*connection, error) { var err error ret := &connection{ws: ws} err = ws.WriteJSON(&MyNode) if err == nil { err = ws.ReadJSON(&ret.node) } if err != nil { return nil, err } ret.name = fmt.Sprintf("%s -> %s (%s)", ws.LocalAddr(), ws.RemoteAddr(), ret.node) ret.sendChan = make(chan interface{}, 1) go ret.sendLoop() return ret, nil }
func (l *listener) handler(ws *websocket.Conn, req *http.Request) { l.lock.Lock() if !l.running { ws.Close() l.lock.Unlock() return } if ws.Subprotocol() != l.proto.Name()+".sp.nanomsg.org" { ws.Close() l.lock.Unlock() return } w := &wsPipe{ws: ws, addr: l.addr, proto: l.proto, open: true} w.dtype = websocket.BinaryMessage w.iswss = l.iswss w.ws.SetReadLimit(int64(l.maxrx)) w.props = make(map[string]interface{}) w.props[mangos.PropLocalAddr] = ws.LocalAddr() w.props[mangos.PropRemoteAddr] = ws.RemoteAddr() if req.TLS != nil { w.props[mangos.PropTLSConnState] = *req.TLS } w.wg.Add(1) l.pending = append(l.pending, w) l.cv.Broadcast() l.lock.Unlock() // We must not return before the socket is closed, because // our caller will close the websocket on our return. w.wg.Wait() }