Début création du fichier du server unicast
This commit is contained in:
parent
e8965385b3
commit
f58890ead1
@ -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()
|
||||
|
||||
}
|
||||
|
42
pkg/network/ServerUnicast.go
Normal file
42
pkg/network/ServerUnicast.go
Normal 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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user