socketOutConnection.h
Go to the documentation of this file.
1 // Copyright 2006-2016 Coppelia Robotics GmbH. All rights reserved.
2 // marc@coppeliarobotics.com
3 // www.coppeliarobotics.com
4 //
5 // -------------------------------------------------------------------
6 // THIS FILE IS DISTRIBUTED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
7 // WARRANTY. THE USER WILL USE IT AT HIS/HER OWN RISK. THE ORIGINAL
8 // AUTHORS AND COPPELIA ROBOTICS GMBH WILL NOT BE LIABLE FOR DATA LOSS,
9 // DAMAGES, LOSS OF PROFITS OR ANY OTHER KIND OF LOSS WHILE USING OR
10 // MISUSING THIS SOFTWARE.
11 //
12 // You are free to use/modify/distribute this file for whatever purpose!
13 // -------------------------------------------------------------------
14 //
15 // This file was automatically created for V-REP release V3.3.2 on August 29th 2016
16 
17 #pragma once
18 
19 #include <vector>
20 #include <string>
21 
22 #ifdef _WIN32
23  #include <Windows.h>
24  #include <process.h>
25  #ifndef QT_COMPIL
26  #pragma message("Adding library: Winmm.lib")
27  #pragma comment(lib,"Winmm.lib")
28  #pragma message("Adding library: Ws2_32.lib")
29  #pragma comment(lib,"Ws2_32.lib")
30  #endif
31 #elif defined (__linux) || defined (__APPLE__)
32  #include <sys/time.h>
33  #include <unistd.h>
34  #include <sys/socket.h>
35  #include <arpa/inet.h>
36  #include <netdb.h>
37  #define SOCKET int
38  #define INVALID_SOCKET (-1)
39 #endif
40 
42 {
43 public:
44  CSocketOutConnection(const char* theConnectionAddress,int theConnectionPort,unsigned short maxPacketSize=250,char headerID1=59,char headerID2=57);
45  virtual ~CSocketOutConnection();
46 
47  int connectToServer();
48  bool sendData(char* data,int dataSize);
49  char* receiveReplyData(int& dataSize);
50 
51 protected:
52  bool _sendSimplePacket(char* packet,int packetLength,unsigned short packetsLeft);
53  int _receiveSimplePacket(std::vector<char>& packet);
54 
55  int _getTimeInMs();
56  int _getTimeDiffInMs(int lastTime);
57 
60 
61 #ifdef _WIN32
62  WSADATA _socketWsaData;
63 #else
64 
65 #endif
66  SOCKET _socketConn;
67  struct sockaddr_in _socketServer;
68 
71  unsigned short _maxPacketSize;
72 };
bool sendData(char *data, int dataSize)
struct sockaddr_in _socketServer
char * receiveReplyData(int &dataSize)
bool _sendSimplePacket(char *packet, int packetLength, unsigned short packetsLeft)
int _getTimeDiffInMs(int lastTime)
unsigned short _maxPacketSize
std::string _socketConnectionAddress
int _receiveSimplePacket(std::vector< char > &packet)
CSocketOutConnection(const char *theConnectionAddress, int theConnectionPort, unsigned short maxPacketSize=250, char headerID1=59, char headerID2=57)