本文整理汇总了C#中Org.Mentalis.Security.Ssl.SecureSocket.SetSocketOption方法的典型用法代码示例。如果您正苦于以下问题:C# SecureSocket.SetSocketOption方法的具体用法?C# SecureSocket.SetSocketOption怎么用?C# SecureSocket.SetSocketOption使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Org.Mentalis.Security.Ssl.SecureSocket
的用法示例。
在下文中一共展示了SecureSocket.SetSocketOption方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: sendraw
//sendraw SSL
public string sendraw (string ipRaw, string portRaw, string payloadRaw, int size, int TimeOut, int retry, bool useSSL) {
IPHostEntry IPHost = Dns.Resolve(ipRaw);
string []aliases = IPHost.Aliases;
IPAddress[] addr = IPHost.AddressList;
IPEndPoint iep ;
SecureProtocol sp;
sp=SecureProtocol.Ssl3;
SecureSocket s=null;
SecurityOptions options = new SecurityOptions(sp);
options.Certificate = null;
options.Protocol=SecureProtocol.Ssl3;
options.Entity = ConnectionEnd.Client;
options.CommonName = ipRaw;
options.VerificationType = CredentialVerification.None;
options.Flags = SecurityFlags.IgnoreMaxProtocol;
options.AllowedAlgorithms = SslAlgorithms.ALL;
while (retry>0){
try {
s = new SecureSocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp, options);
s.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 4000);
s.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 4000);
iep = new IPEndPoint(addr[0],Convert.ToInt32(portRaw));
s.Connect(iep);
ASCIIEncoding asen= new ASCIIEncoding();
byte[] ba=asen.GetBytes(payloadRaw);
s.Send(ba,ba.Length,System.Net.Sockets.SocketFlags.None);
byte[] bb=new byte[size];
int k=1;
string response="";
while (k>0){
k=s.Receive(bb,size,System.Net.Sockets.SocketFlags.None);
response+=Encoding.Default.GetString(bb,0,k);
}
s.Close();
GC.Collect();
GC.WaitForPendingFinalizers();
return response;
}
catch(Exception ex) {
retry--;
Thread.Sleep(1000);
}
}
return "Timeout or retry count exceeded";
}
示例2: sendraw
public string sendraw(string ipRaw, string portRaw, string payloadRaw, int size, int TimeOut, bool useSSL)
{
int retry = (int)updownRetryTCP.Value;
IPHostEntry IPHost = Dns.GetHostEntry(ipRaw);
//IPHostEntry IPHost = Dns.Resolve(ipRaw);
string[] aliases = IPHost.Aliases;
IPAddress[] addr = IPHost.AddressList;
IPEndPoint iep;
SecureProtocol sp;
sp = SecureProtocol.Ssl3;
SecureSocket s = null;
SecurityOptions options = new SecurityOptions(sp);
options.Certificate = null;
options.Protocol = SecureProtocol.Ssl3;
options.Entity = ConnectionEnd.Client;
options.CommonName = ipRaw;
options.VerificationType = CredentialVerification.None;
options.Flags = SecurityFlags.IgnoreMaxProtocol;
options.AllowedAlgorithms = SslAlgorithms.ALL;
while (retry > 0)
{
try
{
s = new SecureSocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp, options);
s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 4000);
s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 4000);
iep = new IPEndPoint(addr[0], Convert.ToInt32(portRaw));
s.Connect(iep);
ASCIIEncoding asen = new ASCIIEncoding();
byte[] ba = asen.GetBytes(payloadRaw);
s.Send(ba, ba.Length, System.Net.Sockets.SocketFlags.None);
byte[] bb = new byte[size];
string response = "";
int k = 1;
while (k > 0)
{
k = s.Receive(bb, size, System.Net.Sockets.SocketFlags.None);
for (int i = 0; i < k; i++)
{
response += Convert.ToChar(bb[i]);
}
}
s.Close();
GC.Collect();
GC.WaitForPendingFinalizers();
return response;
}
catch
{
retry--;
lblStatus.Text = "Network problem - retrying\r\n";
lblNiktoAI.Text = "Network problem - retrying\r\n";
Thread.Sleep(1000);
}
}
return "Retry count (" + updownRetryTCP.Value.ToString() + ") exceeded";
}