Singleclient demo
This commit is contained in:
parent
ff6f3d6f57
commit
7c82a38458
3 changed files with 27 additions and 16 deletions
0
Client/3
0
Client/3
|
@ -3,6 +3,9 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
SWUnixSocket mySocket;
|
SWUnixSocket mySocket;
|
||||||
|
|
|
@ -7,18 +7,20 @@
|
||||||
|
|
||||||
#define BUFLEN 1000000
|
#define BUFLEN 1000000
|
||||||
|
|
||||||
bool machineEndianness() {
|
int main( int argc, char * argv[] ) {
|
||||||
int i = 1;
|
if (argc != 3) { std::cout << "Not the right amount of arguments!\n"; exit(1);}
|
||||||
char *p = (char *) &i;
|
int buffers = atoi(argv[1]);
|
||||||
if (p[0] == 1) {
|
int total_buffersize = atoi(argv[2]);
|
||||||
return false;//little-endian
|
int size_per_buffer = total_buffersize/buffers;
|
||||||
} else {
|
std::cout << "Size per buffer: " << size_per_buffer << "\n";
|
||||||
return true;
|
char ** all_buffers = (char**) calloc(buffers,sizeof(char*));
|
||||||
|
for (int i = 0; i < buffers; i ++ ) {
|
||||||
|
all_buffers[i] = (char*) malloc (size_per_buffer);
|
||||||
|
all_buffers[i][0] = i+'a';
|
||||||
|
}
|
||||||
|
for (int i = 0; i < buffers; i ++ ) {
|
||||||
|
std::cout << "Buffer[" << i << "][0]: " << all_buffers[i][0] << "\n";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
char buffer[BUFLEN];
|
|
||||||
char input[BUFLEN];
|
char input[BUFLEN];
|
||||||
char header[BUFLEN];
|
char header[BUFLEN];
|
||||||
int inp_amount;
|
int inp_amount;
|
||||||
|
@ -26,6 +28,7 @@ int main() {
|
||||||
int position_current = 0;
|
int position_current = 0;
|
||||||
int position_startframe = 0;
|
int position_startframe = 0;
|
||||||
int frame_bodylength = 0;
|
int frame_bodylength = 0;
|
||||||
|
int current_buffer = 0;
|
||||||
SWUnixSocket listener;
|
SWUnixSocket listener;
|
||||||
SWUnixSocket *mySocket = NULL;
|
SWUnixSocket *mySocket = NULL;
|
||||||
SWBaseSocket::SWBaseError BError;
|
SWBaseSocket::SWBaseError BError;
|
||||||
|
@ -48,7 +51,7 @@ int main() {
|
||||||
}
|
}
|
||||||
position_current = 0;
|
position_current = 0;
|
||||||
position_startframe = position_current;
|
position_startframe = position_current;
|
||||||
for(int i = 0; i < 11; i++) { buffer[position_current] = input[i]; position_current ++; }
|
for(int i = 0; i < 11; i++) { all_buffers[current_buffer][position_current] = input[i]; position_current ++; }
|
||||||
frame_bodylength = 0;
|
frame_bodylength = 0;
|
||||||
frame_bodylength += input[3];
|
frame_bodylength += input[3];
|
||||||
frame_bodylength += (input[2] << 8);
|
frame_bodylength += (input[2] << 8);
|
||||||
|
@ -57,19 +60,24 @@ int main() {
|
||||||
std::cout << frame_bodylength << "\n";
|
std::cout << frame_bodylength << "\n";
|
||||||
for (int i = 0; i < frame_bodylength + 4; i++) {
|
for (int i = 0; i < frame_bodylength + 4; i++) {
|
||||||
inp_amount = fread(&input,1,1,stdin);
|
inp_amount = fread(&input,1,1,stdin);
|
||||||
buffer[position_current] = input[0];
|
all_buffers[current_buffer][position_current] = input[0];
|
||||||
position_current ++;
|
position_current ++;
|
||||||
}
|
}
|
||||||
std::cout << "Total message read!\n";
|
std::cout << "Total message read!\n";
|
||||||
if (mySocket) {
|
if (mySocket) {
|
||||||
mySocket->send(&buffer[0], position_current, &BError);
|
std::cout << " mySocket: " << mySocket << "\n";
|
||||||
if ( BError != SWBaseSocket::ok ) {
|
if ( mySocket->fsend(&all_buffers[current_buffer][0], position_current) == -1) {
|
||||||
|
mySocket->disconnect();
|
||||||
|
mySocket->close_fd();
|
||||||
|
std::cout << "Disconnected, closed..." << "\n";
|
||||||
mySocket = 0;
|
mySocket = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
current_buffer++;
|
||||||
|
current_buffer = current_buffer % buffers;
|
||||||
}
|
}
|
||||||
|
|
||||||
// disconnect and clean up
|
// disconnect and clean up
|
||||||
mySocket->disconnect();
|
listener.disconnect();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue