socketInConnection.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 <winsock2.h>
24  #include <Windows.h>
25  #include <process.h>
26  #ifndef QT_COMPIL
27  #pragma message("Adding library: Winmm.lib")
28  #pragma comment(lib,"Winmm.lib")
29  #pragma message("Adding library: Ws2_32.lib")
30  #pragma comment(lib,"Ws2_32.lib")
31  #endif
32  typedef timeval _timeval;
33  typedef int _socklen;
34 #elif defined (__linux) || defined (__APPLE__)
35  #include <string.h>
36  #include <sys/time.h>
37  #include <unistd.h>
38  #include <sys/socket.h>
39  #include <arpa/inet.h>
40  #include <netdb.h>
41  #define SOCKET int
42  #define INVALID_SOCKET (-1)
43  typedef socklen_t _socklen;
44 #endif
45 
46 
48 {
49 public:
50  CSocketInConnection(int theConnectionPort,unsigned short maxPacketSize=250,char headerID1=59,char headerID2=57);
51  virtual ~CSocketInConnection();
52 
53  bool connectToClient();
54  char* receiveData(int& dataSize);
55  bool replyToReceivedData(char* data,int dataSize);
56 
57  std::string getConnectedMachineIP();
58 
59 protected:
60  bool _sendSimplePacket(char* packet,int packetLength,unsigned short packetsLeft);
61  int _receiveSimplePacket(std::vector<char>& packet);
62 
63  unsigned int _getTimeInMs();
64  unsigned int _getTimeDiffInMs(unsigned int lastTime);
65 
66 
67  SOCKET _socketServer;
68  SOCKET _socketClient;
69  struct sockaddr_in _socketLocal;
70 
71  fd_set _socketTheSet;
72 #ifdef _WIN32
73  WSADATA _socketWsaData;
74 #endif /* _WIN32 */
75 
79 
82  unsigned short _maxPacketSize;
83 };
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()
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