From 09cfc96fcfc9c947853973af0c4271325f04ab47 Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Mon, 22 Apr 2024 13:23:48 -0700 Subject: [PATCH] Support creating local BEI connections --- bei.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/bei.go b/bei.go index 9cc3330..183ab1c 100644 --- a/bei.go +++ b/bei.go @@ -142,6 +142,21 @@ func (s *BEIServer) Listen(address string) { } } +func (s *BEIServer) ListenLocal() chan net.Conn { + conns := make(chan net.Conn) + go s.handleLocal(conns) + return conns +} + +func (s *BEIServer) handleLocal(conns chan net.Conn) { + for { + local, remote := net.Pipe() + + conns <- local + go s.handleConnection(remote) + } +} + func parseState(buf []byte) (Board, error) { var stateInts []int for _, v := range bytes.Split(buf, []byte(",")) {