func (m *MLLPReceiver) Run() error {
	defer func() {
		if err := m.listener.Close(); err != nil {
			log.Errorf("MLLP Receiver: closing listener: %v", err)
		}
	}()
	for {
		conn, err := m.listener.(*net.TCPListener).AcceptTCP()
		if err != nil {
			return fmt.Errorf("acceptTCP: %v", err)
		}
		m.metrics.Inc(reconnectsMetric)
		go m.handleConnection(conn)
	}
}
Run starts listening for incoming TCP connections. Only returns in case of an error.
package mllpreceiver
import (
	"fmt"
	"io"
	"net"
	"strconv"
	"time"
	log "github.com/golang/glog"
	"github.com/GoogleCloudPlatform/mllp/mllp_adapter/mllp"
	"github.com/GoogleCloudPlatform/mllp/shared/monitoring"
)
type sender interface {
	Send([]byte) ([]byte, error)
}
type MLLPReceiver struct {
	listener net.Listener
	sender   sender
	port     int
	metrics  *monitoring.Client
	connClosed chan struct{}
}
const (
	reconnectsMetric     = "receiver-reconnects"
	readsMetric          = "receiver-reads"
	handleMessagesMetric = "receiver-handle-messages"
	writesMetric         = "receiver-writes"
)
func NewReceiver(ip string, port int, sender sender, mt *monitoring.Client) (*MLLPReceiver, error) {
	localhost := net.JoinHostPort(ip, strconv.Itoa(port))
	l, err := net.Listen("tcp", localhost)
	if err != nil {
		return nil, fmt.Errorf("listening to port: %v", err)
	}
	tcpAddr, ok := l.Addr().(*net.TCPAddr)
	if !ok {
		return nil, fmt.Errorf("casting %v to TCPAddr: %v", l.Addr(), err)
	}
	mt.NewInt64(reconnectsMetric)
	mt.NewInt64(readsMetric)
	mt.NewInt64(handleMessagesMetric)
	mt.NewInt64(writesMetric)
	return &MLLPReceiver{listener: l, sender: sender, metrics: mt, port: tcpAddr.Port}, nil
}