pest initial setup

This commit is contained in:
Richard 2023-11-26 21:19:00 +01:00
parent b8f2d5d842
commit f0b7401ed7
2 changed files with 61 additions and 1 deletions

View File

@ -12,7 +12,7 @@ type Server interface {
func main() {
var challenge int
flag.IntVar(&challenge, "challenge",10, "Challenge number")
flag.IntVar(&challenge, "challenge",11, "Challenge number")
flag.Parse()
var port uint16
@ -41,6 +41,8 @@ func main() {
server = NewJobServer(port);
case 10:
server = NewVcsServer(port);
case 11:
server = NewPestServer(port);
default:
fmt.Printf("Unknown challenge\n")
os.Exit(1)

58
pest.go Normal file
View File

@ -0,0 +1,58 @@
package main
import (
"net"
"os"
"fmt"
)
type PestServer struct {
port uint16
}
func NewPestServer(port uint16) *PestServer {
return &PestServer{
port,
}
}
type PestSession struct{
con net.Conn
}
func NewPestSession(con net.Conn) *PestSession {
return &PestSession{
con,
}
}
func (s *PestServer) Run() {
addr := fmt.Sprintf("0.0.0.0:%d", s.port)
server, err := net.Listen("tcp", addr)
if err != nil {
fmt.Println("Error listening:", err.Error())
os.Exit(1)
}
defer server.Close()
fmt.Println("PestServer waiting for client...")
for {
connection, err := server.Accept()
if err != nil {
fmt.Println("Error accepting: ", err.Error())
os.Exit(1)
}
fmt.Println("client connected")
s.processClient(connection)
}
}
func (s *PestServer) processClient(con net.Conn) {
session := NewPestSession(con)
go session.pestHandler()
}
func (s *PestSession) pestHandler() {
}