func (s *server) Listen() error {
	s.servingWG.Add(1)
	var err error
	os.Remove(s.filename)
	s.unixListener, err = net.Listen("unix", s.filename)
	return err
}
Listen returns quickly. After Listen has been called, connections to the
server will not immediately fail. In order for them to succeed, Serve()
should be called. This function should only be called once for a given
Server.
package eventsocket
import (
	"context"
	"encoding/json"
	"fmt"
	"log"
	"net"
	"os"
	"sync"
	"time"
	"github.com/m-lab/tcp-info/inetdiag"
)
type TCPEvent int
const (
	Open = TCPEvent(iota)
	Close
)
type FlowEvent struct {
	Event     TCPEvent
	Timestamp time.Time
	UUID      string
	ID        *inetdiag.SockID  
}
type Server interface {
	Listen() error
	Serve(context.Context) error
	FlowCreated(timestamp time.Time, uuid string, sockid inetdiag.SockID)
	FlowDeleted(timestamp time.Time, uuid string)
}
type server struct {
	eventC       chan *FlowEvent
	filename     string
	clients      map[net.Conn]struct{}
	unixListener net.Listener
	mutex        sync.Mutex
	servingWG    sync.WaitGroup
}
func (s *server) addClient(c net.Conn) {
	log.Println("Adding new TCP event client", c)
	s.mutex.Lock()
	defer s.mutex.Unlock()
	s.clients[c] = struct{}{}
}
func (s *server) removeClient(c net.Conn) {
	s.servingWG.Add(1)
	defer s.servingWG.Done()
	s.mutex.Lock()
	defer s.mutex.Unlock()
	_, ok := s.clients[c]
	if !ok {
		log.Println("Tried to remove TCP event client", c, "that was not present")
		return
	}
	delete(s.clients, c)
}
func (s *server) sendToAllListeners(data string) {
	s.mutex.Lock()
	defer s.mutex.Unlock()
	for c := range s.clients {
		_, err := fmt.Fprintln(c, data)
		if err != nil {
			log.Println("Write to client", c, "failed with error", err, " - removing the client.")
			go s.removeClient(c)
			go c.Close()
		}
	}
}
func (s *server) notifyClients(ctx context.Context) {
	s.servingWG.Add(1)
	defer s.servingWG.Done()
	for ctx.Err() == nil {
		event := <-s.eventC
		var b []byte
		var err error
		if event != nil {
			b, err = json.Marshal(*event)
		}
		if event == nil || err != nil {
			log.Printf("WARNING: Bad event received %v (err: %v)\n", event, err)
			continue
		}
		s.sendToAllListeners(string(b))
	}
}