Exemplo n.º 1
0
func tcpHandle(c *net.TCPConn, iface service.ServiceIf) {
	defer c.Close()
	r := bufio.NewReaderSize(c, 4096)
	scanner := bufio.NewScanner(r)
	for scanner.Scan() {
		var buf = scanner.Bytes()
		lineparser.Execute(lineparser.Parse(buf), iface)
	}
}
Exemplo n.º 2
0
func Listener(cfg *config.ConfigBind, iface service.ServiceIf) {
	address, _ := net.ResolveUDPAddr("udp", cfg.Listen)
	log.Info("UDP listening on %s", address)
	listener, err := net.ListenUDP("udp", address)
	if err != nil {
		log.Fatalf("ListenUDP - %s", err)
	}
	defer listener.Close()

	message := make([]byte, MAX_UDP_PACKET_SIZE)
	for {
		n, remaddr, err := listener.ReadFromUDP(message)
		if err != nil {
			log.Error("reading UDP packet from %+v - %s", remaddr, err)
			continue
		}

		lineparser.Execute(lineparser.Parse(message[:n]), iface)
	}
}