Imported more code from the old engine.
[peakengine.git] / engine / include / network / NetworkClient.h
blobac8eb999ad2dabd978e858861ab88d4cf0a961de
1 /*
2 Copyright (C) 2008 Mathias Gottschlag
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in the
6 Software without restriction, including without limitation the rights to use,
7 copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8 Software, and to permit persons to whom the Software is furnished to do so,
9 subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 #ifndef _NETWORKCLIENT_H_
23 #define _NETWORKCLIENT_H_
25 #include "core/Address.h"
26 #include <enet/enet.h>
28 namespace peak
30 class Connection;
33 /**
34 * \brief Network client which can connect to a NetworkServer.
36 class NetworkClient
38 public:
39 NetworkClient();
40 ~NetworkClient();
42 /**
43 * \brief Connects to a local server.
44 * \return Connection to the server, 0 if no connection could be created
46 Connection *init(void);
47 /**
48 * \brief Connects to a remote server.
49 * \return Connection to the server, 0 if no connection could be created
51 Connection *init(Address addr);
52 /**
53 * \brief Disconnects from the server.
55 void shutdown(void);
57 /**
58 * \brief Returns whether the client is connected to a server.
60 bool isConnected(void);
62 /**
63 * \brief Returns the connection to the server.
65 Connection *getConnection(void);
67 /**
68 * \brief Receives incoming data.
70 bool doWork(void);
71 private:
72 ENetHost *host;
73 ENetPeer *peer;
74 Connection *conn;
78 #endif