func (as *TcpServer) onAppConnected(conn *net.TCPConn) { ac := NewApp(conn) as.connMap[conn] = ac log.Printf("New app connection %s\n", ac.conn.RemoteAddr()) for { p, err := skn.ParsePacket(conn) if err != nil { if err != io.EOF { log.Println(err) } break } ac.dispatchAppPacket(p) } as.onAppDisconnected(ac) conn.Close() }
func (m *MatrixClient) onConnected(conn *net.TCPConn) { m.cond.L.Lock() m.conn = conn m.cond.Broadcast() m.cond.L.Unlock() for { p, err := skn.ParsePacket(conn) if err != nil { if err != io.EOF { log.Printf("onConnected - %v\n", err) } break } m.dispatchMessage(p) } conn.Close() m.cond.L.Lock() m.conn = nil m.cond.L.Unlock() go m.connect(conn.RemoteAddr().(*net.TCPAddr)) }
func (t *TcpServer) onConnected(conn *net.TCPConn) { ag := NewAgent(conn) t.Lock() t.agents = append(t.agents, ag) t.Unlock() log.Println("Agent connected", conn.RemoteAddr()) ag.RequestAppInfos() for { p, err := skn.ParsePacket(conn) if err != nil { if err != io.EOF { log.Println(err) } break } ag.dispatchAgentPacket(p) } t.onDisconnected(ag) conn.Close() }