riCOM_cpp
This repository contains the C++ implementation of the riCOM (Real Time Centre Of Mass) algorithm for 4D Scanning electron microscopy.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
SocketConnector.h
Go to the documentation of this file.
1 /* Copyright (C) 2021 Thomas Friedrich, Chu-Ping Yu,
2  * University of Antwerp - All Rights Reserved.
3  * You may use, distribute and modify
4  * this code under the terms of the GPL3 license.
5  * You should have received a copy of the GPL3 license with
6  * this file. If not, please visit:
7  * https://www.gnu.org/licenses/gpl-3.0.en.html
8  *
9  * Authors:
10  * Thomas Friedrich <thomas.friedrich@uantwerpen.be>
11  * Chu-Ping Yu <chu-ping.yu@uantwerpen.be>
12  */
13 
14 #ifndef SOCKET_CONNECTOR_H
15 #define SOCKET_CONNECTOR_H
16 
17 #ifdef _WIN32
18 #pragma comment(lib, "ws2_32.lib")
19 #define _WINSOCK_DEPRECATED_NO_WARNINGS
20 #include <winsock2.h>
21 #include <ws2tcpip.h>
22 #include <io.h>
23 #else
24 #include <arpa/inet.h>
25 #include <unistd.h>
26 #include <cerrno>
27 #include <cstring>
28 #define SOCKET int
29 #define SOCKET_ERROR -1
30 #define INVALID_SOCKET -1
31 #endif
32 
33 #include <string>
34 #include <iostream>
35 
37 {
38 public:
40 
42  std::string ip;
43  int port;
44 
46  int read_data(char *buffer, int data_size);
47  void flush_socket();
48  void connect_socket();
49  void close_socket();
51  b_connected(false),
52  ip("127.0.0.1"),
53  port(6342){};
54 
55 private:
56  struct sockaddr_in address;
57 #ifdef WIN32
58  WSADATA w;
59  const char opt = 1;
60 #else
61  int opt = 1;
62 #endif
63  void handle_socket_errors(const std::string &raised_at);
64 };
65 #endif // SOCKET_CONNECTOR_H
#define INVALID_SOCKET
#define SOCKET
std::string connection_information
std::string ip
int read_data(char *buffer, int data_size)