#include <iostream>
#include <string>
//Network includes.
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
// Other includes.
#include <sys/time.h>
#define PORT 9500
int main(int argc, char**args){
int socket = -1;
struct sockaddr_in servaddr;
char *serverAddress = "127.0.0.1";
socket = ::socket(AF_INET, SOCK_STREAM, 0);
if(socket == -1){
std::cout << "error: unable to create socket" << std::endl;
exit(-1);
}
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(PORT);
inet_pton(AF_INET, serverAddress, &(servaddr.sin_addr));
// Connect ...
if(connect(socket,(const struct sockaddr *)&servaddr,sizeof(struct sockaddr_in)) == 0){
FILE *fin = fdopen(socket, "r");
FILE *fout = fdopen(socket, "w");
bool connectionError = false;
int sizeOfData = 1024;
size_t nObj = 1;
const char *outData = "(sendCommand cmd_ListenToAmp 0 0 0)\n";
int sizeOfString = strlen(outData);
int count = 0;
while(true){
int inData[sizeOfData];
if(fread(reinterpret_cast<char *>(inData), sizeOfData * sizeof(int), nObj,fin) == nObj){
std::cout << "inData count: " << inData[0] << std::endl;
}
else{
connectionError = true;
std::cout << "client: error: read fail" << std::endl;
}
if(connectionError){
exit(0);
}
count++;
sleep(1);
}
}
else{
std::cout << "client: error: failed to connect" << std::endl;
exit(-1);
}
exit(0);
}