-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTCPStream.h
More file actions
26 lines (19 loc) · 759 Bytes
/
TCPStream.h
File metadata and controls
26 lines (19 loc) · 759 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
#ifndef H_TCPSTREAM
#define H_TCPSTREAM
class TCPListener;
class Packet;
class TCPStream
{
friend TCPListener;
private:
int sockfd; //socket file descriptor
TCPStream(int sockfd);
public:
static TCPStream* connectTo(const char* address, int port); //connects to a server and returns a stream pointer if successful
~TCPStream();
int write(void* buff, int len); //writes a buffer of length to the socket, returns bytes sent
int read(void* buff, int len); //reads a buffer of length to from the socket, returns bytes read
void write(Packet* packet); //writes a packet to the socket
Packet* tryReadPacket(); //tries reading a packet and turns a pointer if successfull, keeps reading untill finished
};
#endif