StoreBackEnd/pkg/network/ServerUnicast.go

44 lines
784 B
Go
Raw Normal View History

package network
import (
"_StorBackEnd/pkg/protocol"
"bufio"
"fmt"
"net"
)
type ServerUnicast struct {
Network string
Address string
2022-02-22 08:29:11 +01:00
ReqManager *protocol.RequestManager
}
func (server ServerUnicast) Run() {
listen, err := net.Listen(server.Network, server.Address) // "tcp", "0.0.0.0:58000"
if err != nil {
fmt.Printf("Can't start server : %s\n", err)
return
}
// Attente connexion du FileFrontEnd
con, err := listen.Accept()
if err != nil {
fmt.Printf("Error while accepting client : %s\n", err)
return
} else {
2022-02-22 08:29:11 +01:00
for { // TODO : Extraire cette partie de code
line, err := bufio.NewReader(con).ReadString('\n')
if err != nil {
return
}
result := server.ReqManager.Execute(line)
con.Write(append([]byte(result), '\n'))
}
}
}