-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServerNetwork.h
41 lines (31 loc) · 880 Bytes
/
ServerNetwork.h
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
#pragma once
#include <winsock2.h>
#include <Windows.h>
#include "NetworkServices.h"
#include <ws2tcpip.h>
#include <map>
#include "NetworkData.h"
using namespace std;
#pragma comment (lib, "Ws2_32.lib")
#define DEFAULT_BUFLEN 512
#define DEFAULT_PORT "6881"
class ServerNetwork
{
public:
ServerNetwork(void);
~ServerNetwork(void);
// send data to all clients
void sendToAll(char * packets, int totalSize);
// receive incoming data
int receiveData(unsigned int client_id, char * recvbuf);
// accept new connections
bool acceptNewClient(unsigned int & id);
// Socket to listen for new connections
SOCKET ListenSocket;
// Socket to give to the clients
SOCKET ClientSocket;
// for error checking return values
int iResult;
// table to keep track of each client's socket
std::map<unsigned int, SOCKET> sessions;
};