Skip to content
Snippets Groups Projects
Commit 963bc338 authored by Vytor Calixto's avatar Vytor Calixto :space_invader:
Browse files

Using transmit on the client

parent 9ad40f1c
No related branches found
No related tags found
1 merge request!1Lento
......@@ -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(!receivedMessages.empty() &&
(msg.sequence.to_ulong() != ((receivedMessages.back().sequence.to_ulong()+1)%(MAXSIZE+1))) && (msg.sequence.to_ulong() != receivedMessages.back().sequence.to_ulong()) ){
cout << "Sequence:" << msg.sequence.to_ulong() << "\t";
if(!messages.empty() &&
(msg.sequence.to_ulong() != ((messages.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);
receivedMessages.push_back(msg);
// cout << "Tipo:" << (int)msg.type.to_ulong() << endl;
messages.push_back(msg);
cout << "Tipo:" << (int)msg.type.to_ulong() << endl;
return (int)msg.type.to_ulong();
}
......
......@@ -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);
......
......@@ -5,25 +5,26 @@
int main(){
int sockt = ConexaoRawSocket(DEVICE);
Protocol protocol;
Protocol receiveProtocol, sendProtocol;
cout << "Você está rodando o servidor Caco\n";
while(true){
int status = protocol.recvMessage(sockt);
int status = receiveProtocol.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(protocol.getDataAsString());
cd(receiveProtocol.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){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment