[PD1] Structured client.

Still need to create crypto object and use it to encrypt messages
Need to create TLS still
This commit is contained in:
Afonso Franco 2024-04-17 15:44:38 +01:00
parent 278b8e1a73
commit cdaae8fb7e
Signed by: afonso
SSH key fingerprint: SHA256:aiLbdlPwXKJS5wMnghdtod0SPy8imZjlVvCyUX9DJNk
9 changed files with 252 additions and 110 deletions

View file

@ -0,0 +1,35 @@
package networking
import (
"fmt"
"net"
)
type Server[T any] struct {
listener net.Listener
C chan Connection[T]
}
func NewServer[T any](port int) Server[T]{
listener, err := net.Listen("tcp", fmt.Sprintf("0.0.0.0:%d", port))
if err != nil {
panic("Server could not bind to address")
}
return Server[T]{
listener:listener,
C: make(chan Connection[T]),
}
}
func (s *Server[T]) ListenLoop() {
for {
listenerConn, err := s.listener.Accept()
if err != nil {
panic("Server could not accept connection")
}
conn := NewConnection[T](listenerConn)
s.C <- conn
}
}