[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

@ -3,19 +3,14 @@ package server
import (
"PD1/internal/protocol"
"PD1/internal/utils/networking"
"encoding/json"
"fmt"
)
func clientHandler(connection networking.Connection[protocol.Packet]) {
defer connection.Conn.Close()
jd := json.NewDecoder(connection.Conn)
defer connection.Conn.Close()
for {
var pac protocol.Packet
jd.Decode(&pac)
pac := connection.Receive()
switch pac.Flag {
case protocol.ReqPK:
fmt.Println("ReqPK")
@ -24,7 +19,7 @@ func clientHandler(connection networking.Connection[protocol.Packet]) {
case protocol.ReqMsg:
fmt.Println("ReqMsg")
case protocol.SubmitMsg:
fmt.Println("SubmitMsh")
fmt.Println("SubmitMsg")
}
}
@ -35,7 +30,7 @@ func Run(port int) {
go server.ListenLoop()
for {
//Receive connection via channel
//Receive Connection via channel
conn := <-server.C
//Launch client handler via clientHandler
go clientHandler(conn)