示例#1
0
文件: agent_tcp.go 项目: jarod/skynet
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()
}
示例#2
0
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))
}
示例#3
0
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()
}