riCOM_cpp
This repository contains the C++ implementation of the riCOM (Real Time Centre Of Mass) algorithm for 4D Scanning electron microscopy.
src
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
36
enum
Socket_type
{
SERVER
,
CLIENT
};
37
class
SocketConnector
38
{
39
public
:
40
SOCKET
rc_socket
;
41
SOCKET
client_socket
;
42
Socket_type
socket_type
;
43
44
bool
b_connected
;
45
std::string
ip
;
46
int
port
;
47
48
std::string
connection_information
;
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
();
54
SocketConnector
() :
rc_socket
(
INVALID_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
INVALID_SOCKET
#define INVALID_SOCKET
Definition:
SocketConnector.h:30
Socket_type
Socket_type
Definition:
SocketConnector.h:36
CLIENT
@ CLIENT
Definition:
SocketConnector.h:36
SERVER
@ SERVER
Definition:
SocketConnector.h:36
SOCKET
#define SOCKET
Definition:
SocketConnector.h:28
SocketConnector
Definition:
SocketConnector.h:38
SocketConnector::rc_socket
SOCKET rc_socket
Definition:
SocketConnector.h:40
SocketConnector::accept_socket
void accept_socket()
Definition:
SocketConnector.cpp:63
SocketConnector::socket_type
Socket_type socket_type
Definition:
SocketConnector.h:42
SocketConnector::b_connected
bool b_connected
Definition:
SocketConnector.h:44
SocketConnector::close_socket
void close_socket()
Definition:
SocketConnector.cpp:172
SocketConnector::client_socket
SOCKET client_socket
Definition:
SocketConnector.h:41
SocketConnector::connection_information
std::string connection_information
Definition:
SocketConnector.h:48
SocketConnector::port
int port
Definition:
SocketConnector.h:46
SocketConnector::flush_socket
void flush_socket()
Definition:
SocketConnector.cpp:42
SocketConnector::ip
std::string ip
Definition:
SocketConnector.h:45
SocketConnector::read_data
int read_data(char *buffer, int data_size)
Definition:
SocketConnector.cpp:16
SocketConnector::connect_socket
void connect_socket()
Definition:
SocketConnector.cpp:109
SocketConnector::SocketConnector
SocketConnector()
Definition:
SocketConnector.h:54
Generated by
1.9.1