57 lines
784 B
Go
57 lines
784 B
Go
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
|
|
}
|