StoreBackEnd/pkg/network/ServerUnicast.go

41 lines
673 B
Go
Raw Normal View History

package network
import (
"_StorBackEnd/pkg/protocol"
"bufio"
"fmt"
"net"
)
type ServerUnicast struct {
Network string
Address string
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 {
line, err := bufio.NewReader(con).ReadString('\n')
if err != nil {
return
}
server.ReqManager.Execute(line)
}
}