func (s *Server) Run() {
	go s.AcceptRoutine()    
	go s.DispatchRoutine()  
	go s.TunReadRoutine()   
	go s.TunWriteRoutine()  
	log.Println(logTag, "Server started")
}
Run starts the server and starts to accept clients
package server
import (
	"errors"
	"github.com/lf-edge/edge-home-orchestration-go/internal/common/logmgr"
	"github.com/lf-edge/edge-home-orchestration-go/internal/common/networkhelper"
	"math/rand"
	"net"
	"sync"
	"time"
	"github.com/lf-edge/edge-home-orchestration-go/internal/controller/discoverymgr/mnedc/connectionutil"
	"github.com/lf-edge/edge-home-orchestration-go/internal/controller/discoverymgr/mnedc/tunmgr"
	"github.com/songgao/water"
	"github.com/songgao/water/waterutil"
)
type NetPacket struct {
	Packet []byte
}
type NetPacketIP struct {
	Packet   *NetPacket
	ClientID string
}
type IPTypes struct {
	VirtualIP string
	PrivateIP string
}
const (
	logTag      = "[mnedcserver]"
	channelSize = 200
	packetSize  = 1024
)
var (
	serverIns      *Server
	tunIns         tunmgr.Tun
	networkUtilIns connectionutil.NetworkUtil
	log            = logmgr.GetInstance()
	networkIns     networkhelper.Network
)
type Server struct {
	listener                net.Listener
	intf                    *water.Interface
	virtualIP               net.IP
	netMask                 *net.IPNet
	isAlive                 bool
	clientCount             int
	clients                 map[string]*clientConnection
	clientsLock             sync.Mutex
	clientAddressByDeviceID map[string]string
	clientIDByAddress       map[string]string
	incomingChannel         chan *NetPacket
	outgoingChannel         chan *NetPacket
	incomingIPPacketChan    chan *NetPacketIP
	clientIPInfoByDeviceID  map[string]IPTypes
}
type MNEDCServer interface {
	CreateServer(string, string, bool) (*Server, error)
	Run()
	AcceptRoutine()
	HandleConnection(net.Conn)
	SetVirtualIP(string) string
	DispatchRoutine()
	Route(*NetPacket)
	SetClientAddress(string, string)
	SetClientIP(string, string, string)
	RemoveClient(string)
	GetClientIPMap() map[string]IPTypes
	TunReadRoutine()
	TunWriteRoutine()
	Close() error
	GetVirtualIP() string
}
func init() {
	serverIns = &Server{}
	tunIns = tunmgr.GetInstance()
	networkUtilIns = connectionutil.GetInstance()
	networkIns = networkhelper.GetInstance()
}
func GetInstance() MNEDCServer {
	return serverIns
}
func (s *Server) CreateServer(address, port string, isSecure bool) (*Server, error) {
	logPrefix := logTag + "[NewServer]"
	src := address + ":" + port
	listener, err := networkUtilIns.ListenIP(src, isSecure)
	if err != nil {
		log.Println(logPrefix, "Listen error", err.Error())
		return nil, err
	}
	s.listener = listener
	s.virtualIP = generateServerIP()
	s.netMask = &net.IPNet{
		IP:   s.virtualIP,
		Mask: net.CIDRMask(24, 32),
	}
	s.isAlive = true
	s.clientCount = 1
	s.clients = map[string]*clientConnection{}
	s.clientIDByAddress = map[string]string{}
	s.clientAddressByDeviceID = map[string]string{}
	s.clientIPInfoByDeviceID = map[string]IPTypes{}
	s.incomingChannel = make(chan *NetPacket, channelSize)
	s.outgoingChannel = make(chan *NetPacket, channelSize)
	s.incomingIPPacketChan = make(chan *NetPacketIP, channelSize)
	intf, err := tunIns.CreateTUN()
	if err != nil {
		s.Close()
		return nil, errors.New(logPrefix + " TUN error: " + err.Error())
	}
	s.intf = intf
	setIPError := tunIns.SetTUNIP(s.intf.Name(), s.virtualIP, s.netMask, true)
	if setIPError != nil {
		err = setIPError
	}
	setStatusError := tunIns.SetTUNStatus(s.intf.Name(), true, true)
	if setStatusError != nil {
		err = setStatusError
	}
	if err != nil {
		s.Close()
		return nil, err
	}
	return s, nil
}