func (c *clientConnection) sendRoutine() {
	logPrefix := logTag + "[ClientSendRoutine]"
	for c.isConnected && c.server.isAlive {
		select {
		case pkt := <-c.outgoingChannel:
			_, err := c.conn.Write(pkt.Packet)
			if err != nil {
				log.Println(logPrefix, "Write error for", c.conn.RemoteAddr().String(), err.Error())
				c.hadError(false)
				return
			}
		}
	}
}
writes to the client connection
package server
import (
	"net"
)
type clientConnection struct {
	conn            net.Conn
	server          *Server
	outgoingChannel chan *NetPacket
	localAddr       string
	isConnected     bool
	deviceID        string
}
func (c *clientConnection) initClient(s *Server) {
	logPrefix := logTag + "[initClient]"
	c.outgoingChannel = make(chan *NetPacket, channelSize)
	c.server = s
	log.Printf("%s New connection from %s (%s) initialised\n", logPrefix, c.conn.RemoteAddr().String(), c.deviceID)
	c.localAddr = c.conn.RemoteAddr().String()
	c.isConnected = true
	go c.recvRoutine(s.incomingIPPacketChan)
	go c.sendRoutine()
}
func (c *clientConnection) recvRoutine(sink chan *NetPacketIP) {
	logPrefix := logTag + "[ClientRecvRoutine]"
	vpnbuf := make([]byte, packetSize)
	for c.isConnected && c.server.isAlive {
		n, err := c.conn.Read(vpnbuf)
		if err != nil {
			log.Printf("%s Could not Read from c.conn: %s", logPrefix, err.Error())
			c.hadError(false)
			return
		}
		if n > 0 && err == nil {
			localAddr := c.conn.RemoteAddr()
			c.server.SetClientAddress(c.deviceID, localAddr.String())
			sink <- &NetPacketIP{Packet: &NetPacket{Packet: vpnbuf}, ClientID: c.deviceID}
		}
	}
}