From f58890ead1385b2afd17d67ed0c4bbe504c406ca Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sun, 20 Feb 2022 11:34:10 +0100 Subject: [PATCH] =?UTF-8?q?D=C3=A9but=20cr=C3=A9ation=20du=20fichier=20du?= =?UTF-8?q?=20server=20unicast?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/main.go | 7 ++++-- pkg/network/ServerUnicast.go | 42 ++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 pkg/network/ServerUnicast.go diff --git a/cmd/main.go b/cmd/main.go index efb262e..44b7923 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -12,9 +12,12 @@ const ( func main() { println("StorBackEnd started !") - multicast := network.CreateClientMulticast(MULTICAST_ADDRESS, MULTICAST_SECOND) + //multicast := network.CreateClientMulticast(MULTICAST_ADDRESS, MULTICAST_SECOND) /* go */ - multicast.Run() + //multicast.Run() + + server := network.ServerUnicast{Network: "tcp", Address: "0.0.0.0:58000"} + server.Run() } diff --git a/pkg/network/ServerUnicast.go b/pkg/network/ServerUnicast.go new file mode 100644 index 0000000..1016b46 --- /dev/null +++ b/pkg/network/ServerUnicast.go @@ -0,0 +1,42 @@ +package network + +import ( + "bufio" + "fmt" + "net" +) + +type ServerUnicast struct { + Network string + Address string +} + +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 + } + + // go serverConsole(&cManager) + + for { + 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 + } + + fmt.Printf("MESSAGE : %s\n", line) + } + + } + +}