Start commit 22/02/2022
This commit is contained in:
parent
a8d6197b60
commit
c8de92d99b
@ -2,6 +2,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"_StorBackEnd/pkg/network"
|
"_StorBackEnd/pkg/network"
|
||||||
|
"_StorBackEnd/pkg/protocol"
|
||||||
|
"_StorBackEnd/pkg/protocol/repository"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -12,11 +14,14 @@ const (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
println("StorBackEnd started !")
|
println("StorBackEnd started !")
|
||||||
|
protocolRepository := repository.CreateProtocolRepository()
|
||||||
|
|
||||||
multicast := network.CreateClientMulticast(MULTICAST_ADDRESS, MULTICAST_SECOND)
|
multicast := network.CreateClientMulticast(MULTICAST_ADDRESS, MULTICAST_SECOND, protocolRepository)
|
||||||
go multicast.Run()
|
go multicast.Run()
|
||||||
|
|
||||||
server := network.ServerUnicast{Network: "tcp", Address: UNICAST_ADDRESS}
|
requestManager := protocol.RequestManager{Repository: protocolRepository}
|
||||||
|
|
||||||
|
server := network.ServerUnicast{Network: "tcp", Address: UNICAST_ADDRESS, ReqManager: &requestManager}
|
||||||
server.Run()
|
server.Run()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,17 @@
|
|||||||
package network
|
package network
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"_StorBackEnd/pkg/protocol/repository"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CreateClientMulticast Méthode de construction d'un instance de la stuct ClientMulticast
|
// CreateClientMulticast Méthode de construction d'un instance de la stuct ClientMulticast
|
||||||
func CreateClientMulticast(address string, second time.Duration) ClientMulticast {
|
func CreateClientMulticast(address string, second time.Duration, repository *repository.ProtocolRepository) ClientMulticast {
|
||||||
return ClientMulticast{
|
return ClientMulticast{
|
||||||
address: address,
|
address: address,
|
||||||
second: second,
|
second: second,
|
||||||
|
repository: repository,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,6 +23,9 @@ type ClientMulticast struct {
|
|||||||
|
|
||||||
// second Temps en seconde entre chaque ping
|
// second Temps en seconde entre chaque ping
|
||||||
second time.Duration
|
second time.Duration
|
||||||
|
|
||||||
|
// Repository de protocol permettant de
|
||||||
|
repository *repository.ProtocolRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run Cette méthode démarre une commmunication multicast
|
// Run Cette méthode démarre une commmunication multicast
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
type ServerUnicast struct {
|
type ServerUnicast struct {
|
||||||
Network string
|
Network string
|
||||||
Address string
|
Address string
|
||||||
ReqManager protocol.RequestManager
|
ReqManager *protocol.RequestManager
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server ServerUnicast) Run() {
|
func (server ServerUnicast) Run() {
|
||||||
@ -29,12 +29,15 @@ func (server ServerUnicast) Run() {
|
|||||||
fmt.Printf("Error while accepting client : %s\n", err)
|
fmt.Printf("Error while accepting client : %s\n", err)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
line, err := bufio.NewReader(con).ReadString('\n')
|
for { // TODO : Extraire cette partie de code
|
||||||
if err != nil {
|
line, err := bufio.NewReader(con).ReadString('\n')
|
||||||
return
|
if err != nil {
|
||||||
}
|
return
|
||||||
|
}
|
||||||
|
|
||||||
server.ReqManager.Execute(line)
|
result := server.ReqManager.Execute(line)
|
||||||
|
con.Write(append([]byte(result), '\n'))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,12 +3,12 @@ package protocol
|
|||||||
import "_StorBackEnd/pkg/protocol/repository"
|
import "_StorBackEnd/pkg/protocol/repository"
|
||||||
|
|
||||||
type RequestManager struct {
|
type RequestManager struct {
|
||||||
repository repository.ProtocolRepository
|
Repository *repository.ProtocolRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
func (receiver RequestManager) Execute(request string) string {
|
func (receiver RequestManager) Execute(request string) string {
|
||||||
// On lis ce que l'on reçoit
|
// On lis ce que l'on reçoit
|
||||||
result, executed := receiver.repository.ExecuteReader(request)
|
result, executed := receiver.Repository.ExecuteReader(request)
|
||||||
|
|
||||||
// On renvoie la réponse (Comment pour fichier ?)
|
// On renvoie la réponse (Comment pour fichier ?)
|
||||||
if executed {
|
if executed {
|
||||||
|
@ -4,6 +4,13 @@ import (
|
|||||||
"_StorBackEnd/pkg/protocol"
|
"_StorBackEnd/pkg/protocol"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func CreateProtocolRepository() *ProtocolRepository {
|
||||||
|
return &ProtocolRepository{
|
||||||
|
protocolReaders: make(map[string]*protocol.IProtocolReader),
|
||||||
|
protocolWriters: make(map[string]*protocol.IProtocolWriter),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type ProtocolRepository struct {
|
type ProtocolRepository struct {
|
||||||
protocolReaders map[string]*protocol.IProtocolReader
|
protocolReaders map[string]*protocol.IProtocolReader
|
||||||
protocolWriters map[string]*protocol.IProtocolWriter
|
protocolWriters map[string]*protocol.IProtocolWriter
|
||||||
|
Loading…
Reference in New Issue
Block a user