Пример #1
0
func TestTimeToTimestamp(test *testing.T) {
	t := time.Unix(789697858, 137569000)
	expected := message.Timestamp(789697858137569)
	timestamp := message.TimeToTimestamp(t)

	if timestamp != expected {
		test.Error("Expected", expected, "but got", timestamp)
	}
}
Пример #2
0
func (s *Server) replyTo(client *Client) error {
	b := new(bytes.Buffer)
	err := binary.Write(b, binary.BigEndian, client.received)
	if err != nil {
		return err
	}

	now := message.TimeToTimestamp(time.Now())
	err = binary.Write(b, binary.BigEndian, now)
	if err != nil {
		return err
	}

	_, err = s.conn.WriteToUDP(b.Bytes(), client.addr)
	if err != nil {
		return err
	}

	return nil
}