Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Caco Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bfsc19
Caco Project
Commits
4a8295ec
Commit
4a8295ec
authored
Feb 26, 2023
by
Nico Ramos
Browse files
Options
Downloads
Patches
Plain Diff
aaaaaaa
parent
a32d8bab
No related branches found
No related tags found
1 merge request
!11
Resolve "junção de arquivos e mensagens"
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
headers/client.h
+8
-4
8 additions, 4 deletions
headers/client.h
headers/server.h
+27
-17
27 additions, 17 deletions
headers/server.h
with
35 additions
and
21 deletions
headers/client.h
+
8
−
4
View file @
4a8295ec
...
...
@@ -208,18 +208,16 @@ string client::calc_file_size(string fileName) {
vector
<
char
>
client
::
read_file
(
string
fileName
)
{
fstream
file
;
file
.
open
(
fileName
,
ios
::
in
);
file
.
open
(
fileName
,
ios
::
b
in
ary
);
string
teste
;
vector
<
char
>
fileData
;
char
c
;
while
((
file
.
get
(
c
),
file
.
eof
()
==
false
))
{
fileData
.
push_back
(
c
);
teste
.
push_back
(
c
);
}
file
.
close
();
cout
<<
"vetor criado: "
<<
teste
<<
"
\n
"
;
return
fileData
;
}
...
...
@@ -259,7 +257,13 @@ void client::send_file() {
cout
<<
"Enviando arquivo
\n
"
;
vector
<
char
>
file
=
read_file
(
fileName
);
if
(
file
.
empty
()
||
!
send_message
(
file
,
DADOS
))
if
(
file
.
empty
()
)
{
cout
<<
"Falha ao abrir o arquivo para leitura. Abortado
\n
"
;
return
;
}
if
(
!
send_message
(
file
,
DADOS
))
{
cout
<<
"Limite de timout, arquivo nao foi enviado
\n
"
;
return
;
...
...
This diff is collapsed.
Click to expand it.
headers/server.h
+
27
−
17
View file @
4a8295ec
...
...
@@ -115,7 +115,7 @@ void server::receive_text(frame *f) {
int
lastSeq
=
f
->
get_seq
();
do
{
if
(
!
receive_valid_frame
(
&
f
))
{
continue
;
}
if
(
!
receive_valid_frame
(
&
f
))
{
return
;
}
if
(
f
->
get_tipo
()
!=
TEXTO
)
{
continue
;
}
if
(
f
->
get_seq
()
==
lastSeq
)
{
continue
;
}
...
...
@@ -183,7 +183,7 @@ string server::receive_file_name() {
// Aguarda receber um frame do tipo midia com o nome do arquivo
do
{
if
(
!
receive_valid_frame
(
&
fReceive
))
{
continue
;
}
if
(
!
receive_valid_frame
(
&
fReceive
))
{
return
string
{}
;
}
if
(
fReceive
->
get_tipo
()
!=
MIDIA
)
{
continue
;
}
if
(
strncmp
(
fReceive
->
get_dado
(),
"NAME"
,
4
))
{
continue
;
}
...
...
@@ -200,24 +200,34 @@ string server::receive_file_name() {
return
string
(
fReceive
->
get_dado
()
+
4
);
}
// void server::receive_file_data(){
// vector<frame *> framesMidia;
// receive
int
server
::
receive_file_data
(
string
fileName
)
{
// };
// Abre o arquivo para escrita
ofstream
file
;
file
.
open
(
FILE_DESTINATION
+
"/"
+
fileName
);
if
(
!
file
.
is_open
())
{
cout
<<
"Falha ao criar o arquivo. Abortado
\n
"
;
return
0
;
}
cout
<<
"Arquivo criado com sucesso
\n
"
;
int
server
::
receive_file_data
(
string
fileName
)
{
frame
*
fReceive
;
int
lastSeq
=
-
1
;
int
retries
=
0
;
frame
*
f
;
// Aguarda receber um frame do tipo midia com o nome do arquivo
do
{
if
(
!
receive_valid_frame
(
&
fReceive
))
{
continue
;
}
if
(
fReceive
->
get_tipo
()
!=
MIDIA
)
{
continue
;
}
if
(
strncmp
(
fReceive
->
get_dado
(),
"NAME"
,
4
))
{
continue
;
}
}
while
(
fReceive
->
get_tipo
()
!=
FIMT
);
};
if
(
!
receive_valid_frame
(
&
f
))
{
return
0
;
}
if
(
f
->
get_tipo
()
!=
DADOS
)
{
continue
;
}
if
(
f
->
get_seq
()
==
lastSeq
)
{
continue
;
}
lastSeq
=
f
->
get_seq
();
file
.
write
(
f
->
get_dado
(),
f
->
get_tam
());
}
while
(
f
->
get_tipo
()
!=
FIMT
);
cout
<<
"Arquivo recebido com sucesso
\n
"
;
file
.
close
();
return
1
;
}
void
server
::
receive_midia
(
frame
*
f
)
{
if
(
!
create_received_dir
())
{
return
;
}
...
...
@@ -227,7 +237,7 @@ void server::receive_midia(frame *f) {
if
(
fileName
.
size
()
==
0
)
{
return
;
}
if
(
!
receive_file_data
(
fileName
)
)
{
return
;
}
receive_file_data
(
fileName
)
;
}
// Recebe um frame do cliente
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment