Beispiel #1
0
func (c *Client) handle(conn net.Conn, ws *WorkServer) {
	defer conn.Close()

	reader := gob.NewDecoder(conn)

	c.ClientInfo = new(Hyades.ClientInfo)
	err := reader.Decode(c.ClientInfo)
	if err != nil {
		c.FrameWorkError(err)
		return
	}
	c.Owner.Stats.Announced(c.ClientInfo)

	log.Println(c.ClientInfo.ComputerName, " Connected")

	c.Owner.Stats.Connected()
	defer c.Owner.Stats.Disconnected(c.ClientInfo)

	lc := logicsocket.Wrap(conn)

	workConn := lc.NewConnection(WORK)
	go c.ServiceWork(workConn)

	heartbeatConn := lc.NewConnection(HEARTBEAT)
	c.ServiceHeartBeat(heartbeatConn)

}
Beispiel #2
0
func StartComms(address string, secondaryAddress string) {
	defer func() {
		if err := recover(); err != nil {
			log.Println(err)
		}
	}()
	log.Println("Trying server address", address)
	conn, err := net.Dial("tcp", address)
	if err != nil {
		log.Println(err)
		if secondaryAddress != "" {
			log.Println("Trying server address", secondaryAddress)
			conn, err = net.Dial("tcp", secondaryAddress)
			if err != nil {
				log.Println(err)
				return
			}
		} else {
			log.Println(err)
			return
		}
	}
	defer conn.Close()

	var ci *Hyades.ClientInfo = new(Hyades.ClientInfo)
	log.Println("About to request computer name")

	ci.ComputerName, err = os.Hostname()
	if err != nil {
		if runtime.GOOS == "windows" {
			ci.ComputerName = os.Getenv("COMPUTERNAME")
		}
	}
	ci.OperatingSystem = runtime.GOOS
	log.Println("Acquired computer name; about to send client info")

	connwriter := gob.NewEncoder(conn)
	err = connwriter.Encode(ci)
	if err != nil {
		log.Println("connwriter", err)
		return
	}

	lc := logicsocket.Wrap(conn)

	workConn := lc.NewConnection(WORK)
	log.Println("Starting Work Serivce")
	go ServiceWork(workConn)

	heartbeatConn := lc.NewConnection(HEARTBEAT)
	log.Println("Starting HeartBeat")
	SericeHeartBeat(heartbeatConn)
}