func (s *ProxyServer) Serve(ln net.Listener) error {
	s.tcpListener = ln
	for {
		conn, err := ln.Accept()
		if err != nil {
			return err
		}
		p := &proxyConnection{
			lconn:       conn,
			laddr:       s.LocalTCPAddr,
			raddr:       s.DestTCPAddr,
			erred:       false,
			closeSignal: make(chan bool),
		}
		go p.proxy()
	}
}
Serve starts serving using the provided listener.
Serve blocks indefinitely, or in other
words, until the server is stopped.
package netserver
import (
	"crypto/tls"
	"fmt"
	"net"
	"github.com/caddyserver/caddy"
	"github.com/caddyserver/caddy/caddytls"
)
type ProxyServer struct {
	LocalTCPAddr    string
	DestTCPAddr     string
	tcpListener     net.Listener
	config          *Config
	udpPacketConn   net.PacketConn
	udpClients      map[string]*proxyUDPConnection
	udpClientClosed chan string
}
func NewProxyServer(l string, d string, c *Config) (*ProxyServer, error) {
	return &ProxyServer{
		LocalTCPAddr: l,
		DestTCPAddr:  d,
		config:       c,
		udpClients:   make(map[string]*proxyUDPConnection),
	}, nil
}
func (s *ProxyServer) Listen() (net.Listener, error) {
	var listener net.Listener
	tlsConfig, err := caddytls.MakeTLSConfig([]*caddytls.Config{s.config.TLS})
	if err != nil {
		return nil, err
	}
	inner, err := net.Listen("tcp", fmt.Sprintf("%s", s.LocalTCPAddr))
	if err != nil {
		return nil, err
	}
	if tlsConfig != nil {
		listener = tls.NewListener(inner, tlsConfig)
	} else {
		listener = inner
	}
	return listener, nil
}
func (s *ProxyServer) ListenPacket() (net.PacketConn, error) {
	return net.ListenPacket("udp", fmt.Sprintf("%s", s.LocalTCPAddr))
}