本文整理汇总了C#中ProtocolType.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# ProtocolType.ToString方法的具体用法?C# ProtocolType.ToString怎么用?C# ProtocolType.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProtocolType
的用法示例。
在下文中一共展示了ProtocolType.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MemTcpClient
/// <summary>
/// Initialize and start new TcpClientHandler
/// </summary>
/// <param name="client">TcpClient to Handle</param>
public MemTcpClient(TcpClient client, ProtocolType protocol)
{
_logManager = new LogManager(client.Client.RemoteEndPoint.ToString());
_logManager.Info("MemTcpClient", "\tNew client connected on protocol :" + protocol.ToString());
_client = client;
_stream = _client.GetStream();
_executionManager = new SequentialExecutionManager(_logManager);
_inputBuffer = new byte[MAX_BUFFER_SIZE];
_inputDataStream = new DataStream();
_protocol = protocol;
if (protocol == ProtocolType.Text)
{
_parser = new TextProtocolParser(_inputDataStream, this, _logManager);
_responseManager = new TextResponseManager(_stream, _logManager);
}
else
{
_parser = new BinaryProtocolParser(_inputDataStream, this, _logManager);
_responseManager = new BinaryResponseManager(_stream, _logManager);
}
_responseManager.MemTcpClient = this;
_parser.CommandConsumer = _executionManager;
_executionManager.CommandConsumer = _responseManager;
}
示例2: DeleteForwardingRule
public static void DeleteForwardingRule(int port, ProtocolType protocol)
{
if (string.IsNullOrEmpty(_serviceUrl))
throw new Exception("No UPnP service available or Discover() has not been called");
string body = String.Format("<u:DeletePortMapping xmlns:u=\"urn:schemas-upnp-org:service:WANIPConnection:1\">" +
"<NewRemoteHost></NewRemoteHost><NewExternalPort>{0}</NewExternalPort>"+
"<NewProtocol>{1}</NewProtocol></u:DeletePortMapping>", port, protocol.ToString().ToUpper() );
SOAPRequest(_serviceUrl, body, "DeletePortMapping");
}
示例3: ForwardPort
public static void ForwardPort(int port, ProtocolType protocol, string description)
{
if ( string.IsNullOrEmpty(_serviceUrl) )
throw new Exception("No UPnP service available or Discover() has not been called");
XmlDocument xdoc = SOAPRequest(_serviceUrl, "<u:AddPortMapping xmlns:u=\"urn:schemas-upnp-org:service:WANIPConnection:1\">" +
"<NewRemoteHost></NewRemoteHost><NewExternalPort>" + port.ToString() + "</NewExternalPort><NewProtocol>" + protocol.ToString().ToUpper() + "</NewProtocol>" +
"<NewInternalPort>" + port.ToString() + "</NewInternalPort><NewInternalClient>" + GetLocalIP() +
"</NewInternalClient><NewEnabled>1</NewEnabled><NewPortMappingDescription>" + description +
"</NewPortMappingDescription><NewLeaseDuration>0</NewLeaseDuration></u:AddPortMapping>", "AddPortMapping");
}
示例4: DeleteForwardingRule
public static bool DeleteForwardingRule(int port, ProtocolType protocol)
{
if (string.IsNullOrEmpty(_serviceUrl)) return false;
XmlDocument xdoc = SOAPRequest(_serviceUrl,
"<u:DeletePortMapping xmlns:u=\"urn:schemas-upnp-org:service:WANIPConnection:1\">" +
"<NewRemoteHost></NewRemoteHost>" +
"<NewExternalPort>" + port.ToString() + "</NewExternalPort>" +
"<NewProtocol>" + protocol.ToString().ToUpper() + "</NewProtocol>" +
"</u:DeletePortMapping>", "DeletePortMapping");
return (xdoc != null);
}
示例5: DeleteForwardingRule
public void DeleteForwardingRule(int port, ProtocolType protocol)
{
if (string.IsNullOrEmpty(_serviceUrl))
throw new Exception("No UPnP service available or Discover() has not been called");
XmlDocument xdoc = SOAPRequest(_serviceUrl,
"<u:DeletePortMapping xmlns:u=\"urn:schemas-upnp-org:service:WANIPConnection:1\">" +
"<NewRemoteHost>" +
"</NewRemoteHost>" +
"<NewExternalPort>"+ port+"</NewExternalPort>" +
"<NewProtocol>" + protocol.ToString().ToUpper() + "</NewProtocol>" +
"</u:DeletePortMapping>", "DeletePortMapping");
}
示例6: DeleteForwardingRule
public NatHelperReponseCodes DeleteForwardingRule(int port, ProtocolType protocol)
{
XmlDocument xResponse = null;
string txtError = null;
string SOAPbody = "<u:DeletePortMapping xmlns:u=\"urn:schemas-upnp-org:service:" + ServiceName + ":1\">" +
"<NewRemoteHost>" +
"</NewRemoteHost>" +
"<NewExternalPort>" + port + "</NewExternalPort>" +
"<NewProtocol>" + protocol.ToString().ToUpper() + "</NewProtocol>" +
"</u:DeletePortMapping>";
string SOAPfunction = "DeletePortMapping";
return TrySubmitSOAPRequest(SOAPbody,
SOAPfunction,
ref txtError,
ref xResponse);
}
示例7: ProtocolToString
public static string ProtocolToString(ProtocolType protocol)
{
return protocol.ToString();
}
示例8: ForwardPort
public static bool ForwardPort(int port, ProtocolType protocol, string description)
{
if (string.IsNullOrEmpty(_serviceUrl))
throw new Exception("No UPnP service available or Discover() has not been called");
string body = String.Format("<u:AddPortMapping xmlns:u=\"urn:schemas-upnp-org:service:WANIPConnection:1\">"+
"<NewRemoteHost></NewRemoteHost><NewExternalPort>{0}</NewExternalPort>"+
"<NewProtocol>{1}</NewProtocol><NewInternalPort>{0}</NewInternalPort>" +
"<NewInternalClient>{2}</NewInternalClient><NewEnabled>1</NewEnabled>" +
"<NewPortMappingDescription>{3}</NewPortMappingDescription>"+
"<NewLeaseDuration>0</NewLeaseDuration></u:AddPortMapping>",
port, protocol.ToString().ToUpper(),Dns.GetHostAddresses(Dns.GetHostName())[0], description);
if (SOAPRequest(_serviceUrl, body, "AddPortMapping") != null)
return true;
else
return false;
}
示例9: ForwardPort
public static void ForwardPort(int port, ProtocolType protocol, string description)
{
if (string.IsNullOrEmpty(_serviceUrl))
throw new Exception("No UPnP service available or Discover() has not been called");
IPHostEntry ipEntry = Dns.GetHostByName(Dns.GetHostName());
IPAddress addr = ipEntry.AddressList[0];
XmlDocument xdoc = SOAPRequest(_serviceUrl,
"<m:AddPortMapping xmlns:m=\"urn:schemas-upnp-org:service:WANIPConnection:1\"><NewRemoteHost xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"string\"></NewRemoteHost><NewExternalPort xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"ui2\">" +
port.ToString() + "</NewExternalPort><NewProtocol xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"string\">" +
protocol.ToString().ToUpper() + "</NewProtocol><NewInternalPort xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"ui2\">" +
port.ToString() + "</NewInternalPort><NewInternalClient xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"string\">" +
addr + "</NewInternalClient><NewEnabled xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"boolean\">1</NewEnabled><NewPortMappingDescription xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"string\">" +
description + "</NewPortMappingDescription><NewLeaseDuration xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"ui4\">0</NewLeaseDuration></m:AddPortMapping>",
"AddPortMapping");
}
示例10: Attach
/// <summary>
/// Attaches this AsyncSocket to a new Socket instance, using the given info.
/// </summary>
/// <param name="local">Local interface to use</param>
/// <param name="PType">Protocol Type</param>
public void Attach(IPEndPoint local, ProtocolType PType)
{
endpoint_local = local;
TotalBytesSent = 0;
LocalEP = (EndPoint)local;
Init();
MainSocket = null;
if (PType == ProtocolType.Tcp)
{
MainSocket = new Socket(local.AddressFamily, SocketType.Stream, PType);
}
if (PType == ProtocolType.Udp)
{
MainSocket = new Socket(local.AddressFamily, SocketType.Dgram, PType);
MainSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
}
if (MainSocket != null)
{
MainSocket.Bind(local);
System.Reflection.PropertyInfo pi = MainSocket.GetType().GetProperty("UseOnlyOverlappedIO");
if (pi != null)
{
pi.SetValue(MainSocket, true, null);
}
}
else
{
throw (new Exception(PType.ToString() + " not supported"));
}
}
示例11: ForwardPort
public NatHelperReponseCodes ForwardPort(int port, string localIP, ProtocolType protocol, string description)
{
XmlDocument xResponse = null;
string txtError = null;
string SOAPbody = "<u:AddPortMapping xmlns:u=\"urn:schemas-upnp-org:service:" + ServiceName + ":1\">" +
"<NewRemoteHost></NewRemoteHost><NewExternalPort>" + port.ToString() + "</NewExternalPort><NewProtocol>" + protocol.ToString().ToUpper() + "</NewProtocol>" +
"<NewInternalPort>" + port.ToString() + "</NewInternalPort><NewInternalClient>" + localIP +
"</NewInternalClient><NewEnabled>1</NewEnabled><NewPortMappingDescription>" + description +
"</NewPortMappingDescription><NewLeaseDuration>0</NewLeaseDuration></u:AddPortMapping>";
string SOAPfunction = "AddPortMapping";
return TrySubmitSOAPRequest(SOAPbody,
SOAPfunction,
ref txtError,
ref xResponse);
}
示例12: Resolve
// TODO: Finish adding TCP Support
/// <summary>
///
/// </summary>
/// <param name="dnsServer"></param>
/// <param name="host"></param>
/// <param name="queryType"></param>
/// <param name="queryClass"></param>
/// <param name="protocol"></param>
/// <returns>A <see cref="T:DnDns.Net.Dns.DnsQueryResponse"></see> instance that contains the Dns Answer for the request query.</returns>
/// <PermissionSet>
/// <IPermission class="System.Net.DnsPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// </PermissionSet>
public DnsQueryResponse Resolve(string dnsServer, string host, NsType queryType, NsClass queryClass, ProtocolType protocol)
{
byte[] bDnsQuery = this.BuildDnsRequest(host, queryType, queryClass, protocol);
// Connect to DNS server and get the record for the current server.
IPHostEntry ipe = System.Net.Dns.GetHostEntry(dnsServer);
IPAddress ipa = ipe.AddressList[0];
IPEndPoint ipep = new IPEndPoint(ipa, (int)UdpServices.Domain);
byte[] recvBytes = null;
switch (protocol)
{
case ProtocolType.Tcp:
{
recvBytes = this.ResolveTcp(bDnsQuery, ipep);
break;
}
case ProtocolType.Udp:
{
recvBytes = this.ResolveUdp(bDnsQuery, ipep);
break;
}
default:
{
throw new InvalidOperationException("Invalid Protocol: " + protocol.ToString());
}
}
Trace.Assert(recvBytes != null, "Failed to retrieve data from the remote DNS server.");
DnsQueryResponse dnsQR = new DnsQueryResponse();
dnsQR.ParseResponse(recvBytes);
return dnsQR;
}
示例13: DeletePortMapping
// Port Freigabe löschen
public bool DeletePortMapping(ushort externalPort, ProtocolType protocolType)
{
// Discover() ausgeführt?
if (string.IsNullOrEmpty(m_ServiceURL))
throw new Exception("Discover() has not been called");
try
{
// Request abschicken und Antwort empfangen
XmlDocument xdoc = SOAPRequest(m_ServiceURL,
"<u:DeletePortMapping xmlns:u=\"urn:schemas-upnp-org:service:WANIPConnection:1\">" +
"<NewRemoteHost></NewRemoteHost>" + "<NewExternalPort>" + externalPort.ToString() + "</NewExternalPort>" +
"<NewProtocol>" + protocolType.ToString().ToUpper() + "</NewProtocol>" +
"</u:DeletePortMapping>",
"DeletePortMapping");
return true;
}
catch (Exception e)
{
throw e;
}
}
示例14: ToString
public static string ToString(ProtocolType value)
{
if( value==ProtocolType.Condition )
return "condition";
else if( value==ProtocolType.Device )
return "device";
else if( value==ProtocolType.Drug )
return "drug";
else if( value==ProtocolType.Study )
return "study";
else
throw new ArgumentException("Unrecognized ProtocolType value: " + value.ToString());
}
示例15: CreateForwardingRule
/// <summary>
/// Forwards an external port to the same internal port
/// </summary>
/// <param name="port">The port to map (both external and internal)</param>
/// <param name="protocol">The protocol type to map</param>
/// <param name="description">The description of this mapping</param>
public static void CreateForwardingRule(int port, ProtocolType protocol, string description)
{
IPHostEntry ipEntry = Dns.GetHostEntry(Dns.GetHostName());
IPAddress addr = ipEntry.AddressList[0];
XmlDocument xdoc = SOAPRequest(
"<m:AddPortMapping xmlns:m=\"urn:schemas-upnp-org:service:WANIPConnection:1\"><NewRemoteHost xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"string\"></NewRemoteHost><NewExternalPort xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"ui2\">" +
port.ToString() + "</NewExternalPort><NewProtocol xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"string\">" +
protocol.ToString().ToUpper() + "</NewProtocol><NewInternalPort xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"ui2\">" +
port.ToString() + "</NewInternalPort><NewInternalClient xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"string\">" +
addr + "</NewInternalClient><NewEnabled xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"boolean\">1</NewEnabled><NewPortMappingDescription xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"string\">" +
description + "</NewPortMappingDescription><NewLeaseDuration xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"ui4\">0</NewLeaseDuration></m:AddPortMapping>",
"AddPortMapping");
}