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"?>
<module type="WEB_MODULE" version="4">
<module version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -37,11 +37,11 @@ func main() {
protocolRepository.AddWriter(&helloRule)
// Creation of the SendOkRule
sendOkRule := writers.CreateSendOkRule("^SEND_OK\n$")
sendOkRule := writers.CreateSendOkRule("^SEND_OK\r\n$")
protocolRepository.AddWriter(&sendOkRule)
// Creation of the SendErrorRule
sendErrorRule := writers.CreateSendOkRule("^SEND_ERROR\n$")
sendErrorRule := writers.CreateSendOkRule("^SEND_ERROR\r\n$")
protocolRepository.AddWriter(&sendErrorRule)
/**
@ -52,7 +52,7 @@ func main() {
protocolRepository.AddReader(&eraseFileRule)
// 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)
// Create a Multicast Client & run it

View File

@ -32,12 +32,12 @@ func (server ServerUnicast) Run() {
for { // TODO : Extraire cette partie de code
reader := bufio.NewReader(con)
line, err := reader.ReadString('\n')
println("OK ") // TODO REMOVE
println(line)
println("AH " + line)
if err != nil {
return
}
result := server.ReqManager.Execute(line, reader)
println("Réponse : ", result)
_, _ = 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 {
// On lis ce que l'on reçoit
result, executed, readCb := receiver.Repository.ExecuteReader(request)
println("TESTTESTETTETT")
// On renvoie la réponse (Comment pour fichier ?)
if executed {
if readCb != nil {
@ -23,6 +23,7 @@ func (receiver RequestManager) Execute(request string, reader *bufio.Reader) str
}
return result
} else {
println("HMMM")
// TODO : Renvoyer qu'une erreur est survenue
return "Error occurred while execute command"
}

View File

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