-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSocket.h
More file actions
46 lines (41 loc) · 901 Bytes
/
Copy pathSocket.h
File metadata and controls
46 lines (41 loc) · 901 Bytes
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
#ifndef SOCKET_H
#define SOCKET_H
#include <string>
#include <vector>
#ifdef _WIN32
#include <winsock2.h>
#include <Ws2tcpip.h>
// Link with ws2_32.lib
#pragma comment(lib, "Ws2_32.lib")
#else
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#endif
class Socket
{
public:
Socket(const std::string &ip, const std::string &port);
~Socket();
int sendT(const std::string &buff);
std::string receiveT();
private:
#ifdef _WIN32
int iResult;
WSADATA wsaData;
SOCKET ConnectSocket = INVALID_SOCKET;
struct sockaddr_in clientService;
#else
int sockfd, portno, n;
struct sockaddr_in serv_addr;
struct hostent *server;
#endif
};
std::vector<std::string> splitString(std::string &s);
u_long messageSize(const std::string &);
#endif