[5531] | 1 | /*! |
---|
| 2 | * @file network_socket.h |
---|
| 3 | * Main interface for the network module. Manages all the modules |
---|
| 4 | |
---|
| 5 | */ |
---|
| 6 | |
---|
| 7 | #ifndef _NETWORK_SOCKET |
---|
| 8 | #define _NETWORK_SOCKET |
---|
| 9 | |
---|
[5565] | 10 | /* include this file, it contains some default definitions */ |
---|
| 11 | #include "netdefs.h" |
---|
[5531] | 12 | |
---|
[5565] | 13 | |
---|
[5592] | 14 | /* include base_object.h since all classes are derived from this one */ |
---|
| 15 | #include "base_object.h" |
---|
[5588] | 16 | |
---|
[5592] | 17 | class NetworkSocket : public BaseObject |
---|
[5531] | 18 | { |
---|
[7954] | 19 | public: |
---|
| 20 | NetworkSocket(); |
---|
| 21 | virtual ~NetworkSocket(); |
---|
[5531] | 22 | |
---|
[7954] | 23 | /** |
---|
| 24 | * connect to server on host with port port |
---|
| 25 | * @param host hostname might be xxx.xxx.xxx.xxx or localhost ... |
---|
| 26 | * @param port port to connect to |
---|
| 27 | */ |
---|
| 28 | virtual void connectToServer( std::string host, int port ) = 0; |
---|
| 29 | |
---|
| 30 | /** |
---|
| 31 | * disconnect from server |
---|
| 32 | */ |
---|
| 33 | virtual void disconnectServer() = 0; |
---|
[5565] | 34 | |
---|
[7954] | 35 | /** |
---|
| 36 | * send packet to connected socket. will be recieved as whole packet |
---|
| 37 | * @param data pointer to data to send |
---|
| 38 | * @param length lengt of packet to send |
---|
| 39 | * @return true on success |
---|
| 40 | */ |
---|
| 41 | virtual bool writePacket(byte * data, int length) = 0; |
---|
| 42 | |
---|
| 43 | /** |
---|
| 44 | * read a packet sent by another NetworkSocket |
---|
| 45 | * @param data data will be copied here |
---|
| 46 | * @param maxLength readPacket will not read more than maxLength |
---|
| 47 | * @return bytes read. on error less than zero |
---|
| 48 | */ |
---|
| 49 | virtual int readPacket(byte * data, int maxLength) = 0; |
---|
[5624] | 50 | |
---|
[7954] | 51 | /** |
---|
| 52 | * check if socket is ok |
---|
| 53 | * @return true if socket is ok |
---|
| 54 | */ |
---|
| 55 | inline bool isOk() { return this->bOk; } |
---|
| 56 | |
---|
| 57 | protected: |
---|
| 58 | bool bOk; //!< check for socket status |
---|
[5624] | 59 | |
---|
[5531] | 60 | }; |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | |
---|
[5532] | 64 | #endif /* _NETWORK_SOCKET */ |
---|