-
Notifications
You must be signed in to change notification settings - Fork 0
/
TrSocketClient.cc
42 lines (38 loc) · 1.25 KB
/
TrSocketClient.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "TrSocketClient.hh"
#include <iostream>
TrSocketClient::TrSocketClient() {}
int TrSocketClient::connectToServer() {
int status = connect(socketIdentifier, hostInformationList->ai_addr, hostInformationList->ai_addrlen);
return status;
}
int TrSocketClient::sendData(int *dataPointer, int dataVolume) {
std::cout << "Sending " << *dataPointer << std::endl;
int status = send(socketIdentifier, dataPointer, dataVolume, 0);
return status;
}
int* TrSocketClient::receiveData(int dataWords) {
ssize_t bytesReceived;
int dataBuffer[dataWords];
bytesReceived = recv(socketIdentifier, dataBuffer, dataWords*sizeof(int), 0);
int* dataPointer = (int*)calloc(dataWords, sizeof(int));
for (int word=0; word<dataWords; ++word) {
*dataPointer = dataBuffer[word];
++dataPointer;
}
dataPointer -= dataWords;
return dataPointer;
}
/*
void* TrSocketClient::receiveThreadedData(void *words) {
int dataWords = *(int*)words;
ssize_t bytesReceived;
int dataBuffer[dataWords];
bytesReceived = recv(socketIdentifier, dataBuffer, dataWords*sizeof(int), 0);
int* dataPointer = (int*)calloc(dataWords, sizeof(int));
for (int word=0; word<dataWords; ++word) {
*dataPointer = dataBuffer[word];
++dataPointer;
}
dataPointer -= dataWords;
// return dataPointer;
}*/