Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_NETWORK_SYSTEM_H__
00009 #define __SP_NETWORK_SYSTEM_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013
00014 #ifdef SP_COMPILE_WITH_NETWORKSYSTEM
00015
00016
00017 #include "Framework/Network/spNetworkClient.hpp"
00018 #include "Framework/Network/spNetworkServer.hpp"
00019 #include "Framework/Network/spNetworkPacket.hpp"
00020 #include "Framework/Network/spNetworkSocket.hpp"
00021
00022 #include <list>
00023 #include <boost/function.hpp>
00024
00025
00026 namespace sp
00027 {
00028 namespace network
00029 {
00030
00031
00032 static const u16 DEFAULT_PORT = 8100;
00033
00034
00039 class SP_EXPORT NetworkSystem
00040 {
00041
00042 public:
00043
00044 virtual ~NetworkSystem();
00045
00046
00047
00049 virtual io::stringc getVersion() const;
00050
00052 virtual io::stringc getDescription() const = 0;
00053
00055 virtual NetworkServer* hostServer(u16 Port = DEFAULT_PORT) = 0;
00056
00058 virtual NetworkServer* joinServer(const io::stringc &IPAddress, u16 Port = DEFAULT_PORT) = 0;
00059
00061 virtual void disconnect() = 0;
00062
00070 virtual bool sendPacket(const NetworkPacket &Packet, NetworkMember* Receiver = 0) = 0;
00077 virtual bool receivePacket(NetworkPacket &Packet, NetworkMember* &Sender) = 0;
00078
00088 void processPackets();
00089
00094 bool waitForConnection();
00095
00107 virtual bool popClientJoinStack(NetworkClient* &Client) = 0;
00108
00122 virtual bool popClientLeaveStack(NetworkClient* &Client) = 0;
00123
00128 virtual NetworkMember* getMemberByAddress(const NetworkAddress &Address) = 0;
00129
00130
00131
00136 static io::stringc getHostIPAddress(const io::stringc &HostName);
00137
00139 static io::stringc getOfficialHostName(const io::stringc &HostName);
00140
00146 static std::list<io::stringc> getHostIPAddressList(const io::stringc &HostName);
00147
00153 static std::list<io::stringc> getNetworkMembers();
00154
00156 static std::list<SNetworkAdapter> getNetworkAdapters();
00157
00162 static std::list<io::stringc> getBroadcastIPList();
00163
00164
00165
00167 inline NetworkServer* getServer() const
00168 {
00169 return Server_;
00170 }
00172 inline const std::list<NetworkClient*>& getClientList() const
00173 {
00174 return ClientList_;
00175 }
00176
00178 inline bool isSessionRunning() const
00179 {
00180 return isSessionRunning_;
00181 }
00183 inline bool isConnected() const
00184 {
00185 return isConnected_;
00186 }
00188 inline bool isServer() const
00189 {
00190 return hasOpenedServer_;
00191 }
00192
00193 protected:
00194
00195
00196
00197 NetworkSystem();
00198
00199 #if defined(SP_PLATFORM_WINDOWS)
00200 void createWinSock();
00201 void deleteWinSock();
00202 #endif
00203
00204 void registerMember(NetworkMember* Member);
00205 NetworkMember* getMemberByAddress(const sockaddr_in &SenderAddr);
00206
00207 NetworkClient* createClient(const NetworkAddress &ClientAddr);
00208 void deleteClient(NetworkClient* Client);
00209
00210 void closeNetworkSession();
00211
00212
00213
00214 #if defined(SP_PLATFORM_WINDOWS)
00215 WSADATA WinSock_;
00216 #endif
00217
00218 NetworkServer* Server_;
00219 std::list<NetworkClient*> ClientList_;
00220
00221 std::list<NetworkClient*> ClientJointStack_;
00222 std::list<NetworkClient*> ClientLeaveStack_;
00223
00224 std::map<u64, NetworkMember*> MemberMap_;
00225
00226 bool isSessionRunning_;
00227 bool isConnected_;
00228 bool hasOpenedServer_;
00229
00230 };
00231
00232
00233 }
00234
00235 }
00236
00237
00238 #endif
00239
00240 #endif
00241
00242
00243
00244