riCOM_cpp
This repository contains the C++ implementation of the riCOM (Real Time Centre Of Mass) algorithm for 4D Scanning electron microscopy.
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 
38 {
39 public:
43 
45  std::string ip;
46  int port;
47 
49  int read_data(char *buffer, int data_size);
50  void flush_socket();
51  void connect_socket();
52  void close_socket();
53  void accept_socket();
55  b_connected(false),
56  ip("127.0.0.1"),
57  // port(6342){}; // merlin
58  port(8451){}; // cheetah
59 
60 private:
61  struct sockaddr_in address;
62  struct sockaddr_in c_address;
63  void init_connect();
64  void init_listen();
65 #ifdef WIN32
66  WSADATA w;
67  const char opt = 1;
68 #else
69  int opt = 1;
70 #endif
71  void handle_socket_errors(const std::string &raised_at);
72 };
73 #endif // SOCKET_CONNECTOR_H
#define INVALID_SOCKET
Socket_type
@ CLIENT
@ SERVER
#define SOCKET
Socket_type socket_type
std::string connection_information
std::string ip
int read_data(char *buffer, int data_size)