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) + } + + } + +}