-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTCPSocket.h
47 lines (39 loc) · 897 Bytes
/
TCPSocket.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
#ifndef TCPSOCKET_H
#define TCPSOCKET_H
#include "Socket.h"
#include <set>
class TCPSocket : public Socket
{
public:
TCPSocket();
~TCPSocket();
TCPSocket(int tcp_socket, sockaddr_in* addr);
bool isStreamSocket()
{
return true;
}
// use for server
public:
int wait();
void bindSocket();
void closeSocket();
TCPSocket* acceptSocket();
void removeClientSocket(TCPSocket* pClientSocket);
// use for client
public:
void connect(const char* host, int port = TCP_PORT);
int send(const char* buffer, int buf_size);
int receive(char* buffer, int buf_size);
void setServerSocket(TCPSocket* pTcpSocket)
{
serverSocket = pTcpSocket;
}
TCPSocket* getServerSocket()
{
return serverSocket;
}
private:
std::set<TCPSocket*> socketList;
TCPSocket* serverSocket;
};
#endif // TCPSOCKET_H