Mse à jours du système de réception message + fichier. Il reste à pouvoir vider correctement un fichier lorsqu'il est reçu

This commit is contained in:
Benjamin 2022-03-08 14:48:14 +01:00
parent 30e21ce042
commit bcf8cdd256
5 changed files with 24 additions and 11 deletions

View File

@ -1,9 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4"> <module version="4">
<component name="Go" enabled="true" /> <component name="Go" enabled="true" />
<component name="NewModuleRootManager"> <component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" /> <content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
</module> </module>

View File

@ -37,11 +37,11 @@ func main() {
protocolRepository.AddWriter(&helloRule) protocolRepository.AddWriter(&helloRule)
// Creation of the SendOkRule // Creation of the SendOkRule
sendOkRule := writers.CreateSendOkRule("^SEND_OK\n$") sendOkRule := writers.CreateSendOkRule("^SEND_OK\r\n$")
protocolRepository.AddWriter(&sendOkRule) protocolRepository.AddWriter(&sendOkRule)
// Creation of the SendErrorRule // Creation of the SendErrorRule
sendErrorRule := writers.CreateSendOkRule("^SEND_ERROR\n$") sendErrorRule := writers.CreateSendOkRule("^SEND_ERROR\r\n$")
protocolRepository.AddWriter(&sendErrorRule) protocolRepository.AddWriter(&sendErrorRule)
/** /**
@ -52,7 +52,7 @@ func main() {
protocolRepository.AddReader(&eraseFileRule) protocolRepository.AddReader(&eraseFileRule)
// Creation of the SendFileRule // TODO reset to 50,200 // Creation of the SendFileRule // TODO reset to 50,200
sendFileRule := readers.CreateSendFileRule("^SENDFILE ([A-Za-z0-9.]{1,200} [0-9]{1,10} [A-Za-z0-9.]{50,200})\r\n$") sendFileRule := readers.CreateSendFileRule("^SENDFILE ([A-Za-z0-9.]{1,200}) ([0-9]{1,10}) ([A-Za-z0-9.]{50,200})\r\n$")
protocolRepository.AddReader(&sendFileRule) protocolRepository.AddReader(&sendFileRule)
// Create a Multicast Client & run it // Create a Multicast Client & run it

View File

@ -32,12 +32,12 @@ func (server ServerUnicast) Run() {
for { // TODO : Extraire cette partie de code for { // TODO : Extraire cette partie de code
reader := bufio.NewReader(con) reader := bufio.NewReader(con)
line, err := reader.ReadString('\n') line, err := reader.ReadString('\n')
println("OK ") // TODO REMOVE println("AH " + line)
println(line)
if err != nil { if err != nil {
return return
} }
result := server.ReqManager.Execute(line, reader) result := server.ReqManager.Execute(line, reader)
println("Réponse : ", result)
_, _ = con.Write(append([]byte(result), '\n')) // TODO : ATTENTION laisser les \n _, _ = con.Write(append([]byte(result), '\n')) // TODO : ATTENTION laisser les \n
} }
} }

View File

@ -12,7 +12,7 @@ type RequestManager struct {
func (receiver RequestManager) Execute(request string, reader *bufio.Reader) string { func (receiver RequestManager) Execute(request string, reader *bufio.Reader) string {
// On lis ce que l'on reçoit // On lis ce que l'on reçoit
result, executed, readCb := receiver.Repository.ExecuteReader(request) result, executed, readCb := receiver.Repository.ExecuteReader(request)
println("TESTTESTETTETT")
// On renvoie la réponse (Comment pour fichier ?) // On renvoie la réponse (Comment pour fichier ?)
if executed { if executed {
if readCb != nil { if readCb != nil {
@ -23,6 +23,7 @@ func (receiver RequestManager) Execute(request string, reader *bufio.Reader) str
} }
return result return result
} else { } else {
println("HMMM")
// TODO : Renvoyer qu'une erreur est survenue // TODO : Renvoyer qu'une erreur est survenue
return "Error occurred while execute command" return "Error occurred while execute command"
} }

View File

@ -3,6 +3,7 @@ package readers
import ( import (
"StoreBackEnd/pkg/protocol" "StoreBackEnd/pkg/protocol"
"bufio" "bufio"
"io"
) )
// SendFileRulePrefix Rule command prefix // SendFileRulePrefix Rule command prefix
@ -41,12 +42,24 @@ func (rule SendFileRule) Execute(data string) (string, bool, func(r *bufio.Reade
// function callback // function callback
callback := func(r *bufio.Reader) (string, bool) { callback := func(r *bufio.Reader) (string, bool) {
//var fileContent []byte
// readedByte := -1
/*
for readedByte == -1 || readedByte > 0 {
readedByte, _ = r.Read(fileContent)
println("SendFileRule Reading file ", " - Hey - ", string(readedByte))
}
return "", false */
var fileContent []byte
readedCount, err := io.ReadFull(r, fileContent)
println("Un test ici : ", readedCount, err)
return "SEND_OK\r", true
} }
return "SEND_OK\r\n", true, callback return "SEND_OK\r", true, callback
} else { } else {
return "jjdjd", false, nil println("AHAHAHAHAHAHA")
return "SEND_ERROR\r", false, nil
} }
} }