-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasicSockets.h
More file actions
93 lines (74 loc) · 1.95 KB
/
basicSockets.h
File metadata and controls
93 lines (74 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* basicSockets.h
*
* Created on: Aug 3, 2015
* Author: froike
*/
#include <string>
using namespace std;
#ifndef BMRNET_H_
#define BMRNET_H_
#ifdef _WIN32
#include<winsock2.h>
#endif
class BmrNet {
private:
char * host;
unsigned int port;
bool is_JustServer;
int socketFd;
#ifdef _WIN32
PCSTR Cport;
WSADATA wsa;
DWORD dwRetval;
#endif
public:
/**
* Constructor for servers and clients, got the host and the port for connect or listen.
* After creation call listenNow() or connectNow() function.
*/
BmrNet(char * host, int port);
/**
* Constructor for servers only. got the port it will listen to.
* After creation call listenNow() function.
*/
BmrNet(int portno);
/**
* got data and send it to the other side, wait for response and return it.
* return pointer for the data that recived.
*/
void* sendAndRecive(const void* data, int get_size, int send_size);
/**
* got data and send it just after receiving someting from the other side
* and return what it received.
* return pointer for the data that recived.
*/
void* reciveAndSend(const void* data, int get_size, int send_size);
/**
* got function fun(void*, int) and after receiving someting from the other side it will call fun(data, get_size)
* send the results back to the other side and return what it received.
* return pointer for the data that recived.
*/
void* reciveAndSend(void* (*fun)(void*,int), int get_size, int send_size);
virtual ~BmrNet();
/**
* Start listen on the given port.
*/
bool listenNow();
/**
* Try to connect to server by given host and port.
* return true for success or false for failure.
*/
bool connectNow();
/**
* Send Data to the other side.
* return true for success or false for failure.
*/
bool sendMsg(const void* data, int size);
/**
* Recive data from other side.
* return true for success or false for failure.
*/
bool reciveMsg(void* buff, int buffSize);
};
#endif /* BMRNET_H_ */