func (server *Server) accept() {
	defer server.listener.Close()
	for {
		conn, err := server.listener.Accept()
		if err != nil {
			return
		}
		server.handleConn(textproto.NewConn(conn))
	}
}
accept incoming connections.
package beanstalk
import (
	"bytes"
	"context"
	"errors"
	"net"
	"net/textproto"
	"sync"
	"testing"
	"time"
)
type Line struct {
	lineno int
	line   string
}
func (line Line) At(lineno int, s string) bool {
	return lineno == line.lineno && s == line.line
}
type Server struct {
	listener  net.Listener
	mu        sync.RWMutex
	lineno    int
	handler   func(line Line) string
	closeC    chan struct{}
	closeOnce sync.Once
}
func NewServer() *Server {
	listener, err := net.Listen("tcp", "localhost:0")
	if err != nil {
		panic("Unable to set up listening socket for text beanstalk server: " + err.Error())
	}
	server := &Server{listener: listener, closeC: make(chan struct{})}
	go server.accept()
	return server
}
func (server *Server) Close() {
	server.closeOnce.Do(func() {
		close(server.closeC)
		_ = server.listener.Close()
	})
}