-
Notifications
You must be signed in to change notification settings - Fork 1
/
TCPClient.h
66 lines (45 loc) · 1.24 KB
/
TCPClient.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
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
//
// Created by kurox on 18-4-10.
//
#ifndef CLION_TCPSOCKET_H
#define CLION_TCPSOCKET_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/select.h>
#include <fcntl.h>
#include <sys/time.h>
#include <errno.h>
#include <time.h>
#include <signal.h>
#include <getopt.h>
#include <arpa/inet.h>
#include "common.h"
class TCPClient {
public:
TCPClient(u_int32_t ip, uint16_t port);
~TCPClient();
void setOnRecvCallBack(void(*callBack)(ClientData *));
void setOnConnectedCallBack(void (*callBack)(ClientData *));
void setOnFinCallBack(void (*callBack)(ClientData *));
void ConnectServer();
void SendPacket(char *playload, size_t len);
private:
u_int32_t ip;
uint16_t portno;
struct sockaddr_in serv_addr;
//回调函数
void (*onRecvCallBack)(ClientData *data);
void (*onConnectedCallBack)(ClientData *data);
void (*onFinCallBack)(ClientData *data);
ClientData *cli_data = nullptr;
int tcp_recv_server(int clifd, char *data, size_t len);
int tcp_send_server(int serverfd, const char *data, size_t len);
void tcp_block();
};
#endif //CLION_TCPSOCKET_H