shelldoor/servers/server.go

58 lines
784 B
Go
Raw Normal View History

2024-09-25 22:56:40 +03:00
package servers
import (
"log"
"net"
)
type BotRequest struct {
}
type BotResponse struct {
}
type ClientRequest struct {
}
type ClientResponse struct {
Error string
Text string
}
type Server struct {
addr string
listenner net.Listener
bots []*Bot
clients []*Client
}
func NewServer(addr string) (*Server, error) {
srv := &Server{}
srv.addr = addr
return srv, nil
}
func (srv *Server) HandleConn(conn net.Conn) {
defer conn.Close()
}
func (srv *Server) ListenAndServe() error {
var err error
srv.listenner, err = net.Listen("tcp", srv.addr)
if err != nil {
return err
}
for {
conn, err := srv.listenner.Accept()
if err != nil {
log.Printf("listener.Accept(...): %s\n", err)
continue
}
go srv.HandleConn(conn)
}
return nil
}