增加网络资源NetUri
This commit is contained in:
parent
86ad9a94ec
commit
4d388f48c4
|
@ -5,7 +5,7 @@
|
|||
#include "Core\SString.h"
|
||||
|
||||
// IP协议类型
|
||||
enum ProtocolType
|
||||
enum class ProtocolType
|
||||
{
|
||||
Ip = 0,
|
||||
Icmp = 1,
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
#include "NetUri.h"
|
||||
#include "Config.h"
|
||||
|
||||
/******************************** NetUri ********************************/
|
||||
|
||||
NetUri::NetUri()
|
||||
{
|
||||
Type = NetType::Unknown;
|
||||
Address = IPAddress::Any();
|
||||
Port = 0;
|
||||
}
|
||||
|
||||
/*NetUri::NetUri(const String& uri) : NetUri()
|
||||
{
|
||||
int p = uri.IndexOf("://");
|
||||
if(p)
|
||||
{
|
||||
|
||||
}
|
||||
}*/
|
||||
|
||||
NetUri::NetUri(NetType type, const IPAddress& addr, ushort port)
|
||||
{
|
||||
Type = type;
|
||||
Address = addr;
|
||||
Port = port;
|
||||
}
|
||||
|
||||
NetUri::NetUri(NetType type, const String& host, ushort port)
|
||||
{
|
||||
Type = type;
|
||||
Address = IPAddress::Any();
|
||||
Host = host;
|
||||
Port = port;
|
||||
}
|
||||
|
||||
String& NetUri::ToStr(String& str) const
|
||||
{
|
||||
if(IsTcp())
|
||||
str += "Tcp";
|
||||
else if(IsUdp())
|
||||
str += "Udp";
|
||||
|
||||
str += "://";
|
||||
|
||||
if(Host)
|
||||
str += Host;
|
||||
else
|
||||
str += Address;
|
||||
|
||||
str += ":";
|
||||
|
||||
str += Port;
|
||||
|
||||
return str;
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
#ifndef _NetUri_H_
|
||||
#define _NetUri_H_
|
||||
|
||||
#include "IPAddress.h"
|
||||
#include "IPEndPoint.h"
|
||||
#include "MacAddress.h"
|
||||
#include "Delegate.h"
|
||||
|
||||
// 协议类型
|
||||
enum class NetType
|
||||
{
|
||||
Unknown = 0,
|
||||
Tcp = 6,
|
||||
Udp = 17,
|
||||
};
|
||||
|
||||
// 网络资源
|
||||
class NetUri : public Object
|
||||
{
|
||||
public:
|
||||
NetType Type; // 协议类型
|
||||
IPAddress Address; // 地址
|
||||
ushort Port; // 端口
|
||||
String Host; // 远程地址,字符串格式,可能是IP字符串
|
||||
|
||||
NetUri();
|
||||
NetUri(const String& uri);
|
||||
NetUri(NetType type, const IPAddress& addr, ushort port);
|
||||
NetUri(NetType type, const String& host, ushort port);
|
||||
|
||||
bool IsTcp() const { return Type == NetType::Tcp; }
|
||||
bool IsUdp() const { return Type == NetType::Udp; }
|
||||
|
||||
virtual String& ToStr(String& str) const;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue