18 #define HEADER_LENGTH 6 // byte1=id1, byte2=id2, byte3+byte4=packetSize, byte5+byte6=packetsLeftToRead 29 #if defined (__linux) || defined (__APPLE__) 43 #elif defined (__linux) || defined (__APPLE__) 60 if (WSAStartup(0x101,&_socketWsaData)!=0)
78 struct sockaddr_in from;
79 int fromlen=
sizeof(from);
96 std::vector<char> receivedData;
99 std::vector<char> inDat;
106 receivedData.insert(receivedData.end(),inDat.begin(),inDat.end());
109 dataSize=int(receivedData.size());
110 char* retBuff=
new char[dataSize];
111 for (
int i=0;i<dataSize;i++)
112 retBuff[i]=receivedData[i];
156 return(
"NONE (reception line is not open)");
166 unsigned short s=(
unsigned short)packetLength;
170 ((
unsigned short*)(header+2))[0]=s;
171 ((
unsigned short*)(header+2))[1]=packetsLeft;
173 std::vector<char> toSend;
175 toSend.push_back(header[i]);
176 for (
int i=0;i<packetLength;i++)
177 toSend.push_back(packet[i]);
179 return(send(
_socketClient,&toSend[0],packetLength+HEADER_LENGTH,0)==packetLength+HEADER_LENGTH);
190 #if defined (__linux) || defined (__APPLE__) 213 unsigned short dataLength=((
unsigned short*)(headerAndSize+2))[0];
216 packet.resize(dataLength,0);
219 while(totalReceived!=dataLength)
221 int nb=recv(
_socketClient,&packet[0]+totalReceived,dataLength-totalReceived,0);
228 if (totalReceived!=dataLength)
230 return(
int(((
unsigned short*)(headerAndSize+2))[1]));
240 return(timeGetTime()&0x03ffffff);
244 #if defined (__linux) || defined (__APPLE__) 248 unsigned int result=0;
249 if (gettimeofday(&tv,NULL)==0)
250 result=(tv.tv_sec*1000+tv.tv_usec/1000)&0x03ffffff;
258 if (currentTime<lastTime)
259 return(currentTime+0x03ffffff-lastTime);
260 return(currentTime-lastTime);
std::string _socketConnectedMachineIP
bool _sendSimplePacket(char *packet, int packetLength, unsigned short packetsLeft)
CSocketInConnection(int theConnectionPort, unsigned short maxPacketSize=250, char headerID1=59, char headerID2=57)
char * receiveData(int &dataSize)
std::string getConnectedMachineIP()
virtual ~CSocketInConnection()
unsigned int _getTimeInMs()
unsigned short _maxPacketSize
unsigned int _getTimeDiffInMs(unsigned int lastTime)
bool replyToReceivedData(char *data, int dataSize)
int _receiveSimplePacket(std::vector< char > &packet)
struct sockaddr_in _socketLocal
int _socketConnectionPort