Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Caco
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Harbor Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Vytor Calixto
Caco
Commits
963bc338
Commit
963bc338
authored
9 years ago
by
Vytor Calixto
Browse files
Options
Downloads
Patches
Plain Diff
Using transmit on the client
parent
9ad40f1c
No related branches found
No related tags found
1 merge request
!1
Lento
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
Protocol.cpp
+9
-9
9 additions, 9 deletions
Protocol.cpp
Protocol.h
+1
-2
1 addition, 2 deletions
Protocol.h
server.cpp
+10
-9
10 additions, 9 deletions
server.cpp
with
20 additions
and
20 deletions
Protocol.cpp
+
9
−
9
View file @
963bc338
...
...
@@ -16,7 +16,6 @@ bool Protocol::sendMessages(int socket) {
int
status
=
sendMessage
(
socket
,
i
);
if
(
status
<
0
)
{
success
=
false
;
cout
<<
"fail"
<<
endl
;
}
}
return
success
;
...
...
@@ -49,7 +48,7 @@ string Protocol::getDataAsString(){
return
str
;
}
void
Protocol
::
setData
(
vector
<
BYTE
>
data
,
int
type
){
int
Protocol
::
setData
(
vector
<
BYTE
>
data
,
int
type
){
vector
<
BYTE
>::
const_iterator
first
,
last
;
int
i
;
for
(
i
=
0
;
i
<=
((
int
)
data
.
size
())
-
MAXSIZE
;
i
+=
MAXSIZE
){
...
...
@@ -82,23 +81,24 @@ void Protocol::setData(vector<BYTE> data, int type){
msg
.
calcParity
();
messages
.
push_back
(
msg
);
}
return
messages
.
size
();
}
int
Protocol
::
recvMessage
(
int
sockt
){
BYTE
dataRec
[
MAXSIZE
+
4
];
int
r
=
recv
(
sockt
,
dataRec
,
MAXSIZE
+
4
,
0
);
cout
<<
bitset
<
8
>
(
dataRec
[
0
])
<<
"|"
<<
bitset
<
8
>
(
dataRec
[
1
])
<<
"|"
<<
bitset
<
8
>
(
dataRec
[
2
])
<<
"|"
<<
bitset
<
8
>
(
dataRec
[
3
])
<<
"|
\t
"
;
//
cout << "recv response: " << r << endl;
cout
<<
"recv response: "
<<
r
<<
endl
;
if
(
dataRec
[
0
]
!=
BEGIN
){
return
NOISE
;
}
Message
msg
=
Message
();
int
size
=
(
int
)(
dataRec
[
1
]
>>
2
);
//
cout << "Tamanho:" << size << "\t";
cout
<<
"Tamanho:"
<<
size
<<
"
\t
"
;
msg
.
setBitFields
(
dataRec
[
0
],
dataRec
[
1
],
dataRec
[
2
],
dataRec
[
size
+
3
]);
//
cout << "Sequence:" << msg.sequence.to_ulong() << "\t";
if
(
!
receivedM
essages
.
empty
()
&&
(
msg
.
sequence
.
to_ulong
()
!=
((
receivedM
essages
.
back
().
sequence
.
to_ulong
()
+
1
)
%
(
MAXSIZE
+
1
)))
&&
(
msg
.
sequence
.
to_ulong
()
!=
receivedMessages
.
back
().
sequence
.
to_ulong
())
){
cout
<<
"Sequence:"
<<
msg
.
sequence
.
to_ulong
()
<<
"
\t
"
;
if
(
!
m
essages
.
empty
()
&&
(
msg
.
sequence
.
to_ulong
()
!=
((
m
essages
.
back
().
sequence
.
to_ulong
()
+
1
)
%
(
MAXSIZE
+
1
)))){
return
SEQ_MISS
;
}
if
(
!
msg
.
checkParity
()){
...
...
@@ -111,8 +111,8 @@ int Protocol::recvMessage(int sockt){
BYTE
msgData
[
size
];
memcpy
(
msgData
,
dataRec
+
3
,
size
);
msg
.
data
.
insert
(
msg
.
data
.
end
(),
msgData
,
msgData
+
size
);
receivedM
essages
.
push_back
(
msg
);
//
cout << "Tipo:" << (int)msg.type.to_ulong() << endl;
m
essages
.
push_back
(
msg
);
cout
<<
"Tipo:"
<<
(
int
)
msg
.
type
.
to_ulong
()
<<
endl
;
return
(
int
)
msg
.
type
.
to_ulong
();
}
...
...
This diff is collapsed.
Click to expand it.
Protocol.h
+
1
−
2
View file @
963bc338
...
...
@@ -7,7 +7,6 @@ class Protocol{
private:
vector
<
Message
>
messages
;
vector
<
Message
>
receivedMessages
;
int
timeout
;
public:
bool
sendMessages
(
int
socket
);
...
...
@@ -15,7 +14,7 @@ public:
vector
<
Message
>
getMessages
();
void
setMessages
(
vector
<
Message
>
messages
);
vector
<
BYTE
>
getData
();
void
setData
(
vector
<
BYTE
>
data
,
int
type
);
int
setData
(
vector
<
BYTE
>
data
,
int
type
);
string
getDataAsString
();
int
recvMessage
(
int
sockt
);
void
addMessage
(
Message
msg
);
...
...
This diff is collapsed.
Click to expand it.
server.cpp
+
10
−
9
View file @
963bc338
...
...
@@ -5,25 +5,26 @@
int
main
(){
int
sockt
=
ConexaoRawSocket
(
DEVICE
);
Protocol
p
rotocol
;
Protocol
receiveProtocol
,
sendP
rotocol
;
cout
<<
"Você está rodando o servidor Caco
\n
"
;
while
(
true
){
int
status
=
p
rotocol
.
recvMessage
(
sockt
);
int
status
=
receiveP
rotocol
.
recvMessage
(
sockt
);
cout
<<
"status: "
<<
status
<<
endl
;
// cout << protocol.getDataAsString() << endl;
if
(
status
>
0
){
if
(
status
==
ENDTX
){
protocol
=
Protocol
();
//
protocol = Protocol();
//TODO: send ACK
}
else
if
(
status
==
CD
){
cout
<<
"Recebeu CD
\n
"
;
cd
(
p
rotocol
.
getDataAsString
());
cd
(
receiveP
rotocol
.
getDataAsString
());
}
else
if
(
status
==
LS
){
cout
<<
protocol
.
getDataAsString
()
<<
endl
;
string
output
=
ls
(
protocol
.
getDataAsString
());
string
output
=
ls
(
receiveProtocol
.
getDataAsString
());
cout
<<
"LS: "
<<
output
<<
endl
;
protocol
.
setData
(
vector
<
BYTE
>
(
output
.
begin
(),
output
.
end
()),
OUTPUT
);
protocol
.
sendMessages
(
sockt
);
// receiveProtocol = Protocol();
receiveProtocol
.
setData
(
vector
<
BYTE
>
(
output
.
begin
(),
output
.
end
()),
OUTPUT
);
receiveProtocol
.
sendMessages
(
sockt
);
// sendProtocol = Protocol();
}
else
if
(
status
==
PUT
){
//TODO
}
else
if
(
status
==
GET
){
...
...
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