Début création du fichier du server unicast

This commit is contained in:
Benjamin Lejeune 2022-02-20 11:34:10 +01:00
parent e8965385b3
commit f58890ead1
2 changed files with 47 additions and 2 deletions

View File

@ -12,9 +12,12 @@ const (
func main() { func main() {
println("StorBackEnd started !") println("StorBackEnd started !")
multicast := network.CreateClientMulticast(MULTICAST_ADDRESS, MULTICAST_SECOND) //multicast := network.CreateClientMulticast(MULTICAST_ADDRESS, MULTICAST_SECOND)
/* go */ /* go */
multicast.Run() //multicast.Run()
server := network.ServerUnicast{Network: "tcp", Address: "0.0.0.0:58000"}
server.Run()
} }

View File

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