form1.cs
来自「语音视频功能 里面实现了基本的QQ与语音对话」· CS 代码 · 共 196 行
CS
196 行
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Org.Mentalis.Security.Ssl;
using System.Net;
using Org.Mentalis.Security.Certificates;
using System.Net.Sockets;
namespace gowk.net
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.Button button1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// richTextBox1
//
this.richTextBox1.Location = new System.Drawing.Point(32, 32);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.TabIndex = 0;
this.richTextBox1.Text = "richTextBox1";
//
// button1
//
this.button1.Location = new System.Drawing.Point(216, 144);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button1);
this.Controls.Add(this.richTextBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
string xml="<stream:stream xmlns:stream=\"http://etherx.jabber.org/streams\" id=\"a2dfb075\" xmlns=\"jabber:client\" to=\"jabber.org\" version=\"1.0\">";
gowk.net.Sockets.GSecureSocket ssss;
public void sss()
{
SecurityOptions options = new SecurityOptions(Org.Mentalis.Security.Ssl.SecureProtocol.Tls1|Org.Mentalis.Security.Ssl.SecureProtocol.Ssl3);
// First we create a new SecurityOptions instance
// SecurityOptions objects hold information about the security
// protocols the SecureSocket should use and how the SecureSocket
// should react in certain situations.
// SecurityOptions options = new SecurityOptions(sp);
// The Certificate field holds a certificate associated with
// a client [you, for instance]. Because client certificates
// are not often used for HTTP over SSL or TLS, we'll simply
// set this field to a null reference.
options.Certificate = null;
// The Entity specifies whether the SecureSocket should act
// as a client socket or as a server socket. In this case,
// it should act as a client socket.
options.Entity = ConnectionEnd.Client;
// The CommonName field specifies the name of the remote
// party we're connecting to. This is usually the domain name
// of the remote host.
options.CommonName = "www.xfocus.net";
// The VerificationType field specifies how we intend to verify
// the certificate. In this case, we tell the SecureSocket that
// we will manually verify the certificate. Look in the documentation
// for other options.
options.VerificationType = CredentialVerification.Manual;
// When specifying the CredentialVerification.Manual option, we
// must also specify a CertVerifyEventHandler delegate that will
// be called when the SecureSocket receives the remote certificate.
// The Verifier field holds this delegate. If no manual verification
// is done, this field can be set to a null reference.
options.Verifier = new CertVerifyEventHandler(OnVerify);
// The Flags field specifies which flags should be used for the
// connection. In this case, we will simply use the default behavior.
options.Flags = SecurityFlags.Default;
// Allow only secure ciphers to be used. If the server only supports
// weak encryption, the connections will be shut down.
options.AllowedAlgorithms = SslAlgorithms.SECURE_CIPHERS;
// create a new SecureSocket instance and initialize it with
// the security options we specified above.
this.ssss=new gowk.net.Sockets.GSecureSocket(options);
System.Net.IPEndPoint iep=new System.Net.IPEndPoint(System.Net.Dns.Resolve("www.xfocus.net").AddressList[0],80);
System.Diagnostics.Trace.WriteLine(iep.ToString());
this.ssss.Proxy=new Proxy();
this.ssss.Proxy.Host="192.168.0.1";
this.ssss.Proxy.Port=1080;
this.ssss.Connect("www.xfocus.net",80);
this.ssss.Send(System.Text.Encoding.UTF8.GetBytes("get /index.php \r\n\r\n"));
byte[] buffer=new byte[1024];
int cnt=this.ssss.Receive(buffer);
MessageBox.Show(System.Text.Encoding.ASCII.GetString(buffer,0,cnt));
//this.ssss.Shutdown(System.Net.Sockets.SocketShutdown.Both);
this.ssss.Close();
}
/// <summary>
/// Verifies a certificate received from the remote host.
/// </summary>
/// <param name="socket">The SecureSocket that received the certificate.</param>
/// <param name="remote">The received certificate.</param>
/// <param name="e">The event parameters.</param>
protected void OnVerify(SecureSocket socket, Certificate remote, CertificateChain chain, VerifyEventArgs e)
{
CertificateChain cc = new CertificateChain(remote);
Console.WriteLine("\r\nServer Certificate:\r\n-------------------");
Console.WriteLine(remote.ToString(true));
Console.Write("\r\nServer Certificate Verification:\r\n--------------------------------\r\n -> ");
Console.WriteLine(cc.VerifyChain(socket.CommonName, AuthType.Server).ToString() + "\r\n");
}
gowk.net.Sockets.GSecureSocket s;
private void button1_Click(object sender, System.EventArgs e)
{
this.sss();return;
Org.Mentalis.Security.Ssl.SecurityOptions opt=new Org.Mentalis.Security.Ssl.SecurityOptions(Org.Mentalis.Security.Ssl.SecureProtocol.Tls1|Org.Mentalis.Security.Ssl.SecureProtocol.Ssl3);
s=new gowk.net.Sockets.GSecureSocket(opt);
s.Proxy=new Proxy();
s.Proxy.Host="127.0.0.1";
s.Proxy.Port=1080;
s.AsyncInvoke(new AsyncCallback(this.ss));
}
void ss(System.IAsyncResult iar)
{
s.Connect("jabber.org",5223);
// s.StartSSL();
s.Send(System.Text.Encoding.Default.GetBytes("<stream>"));
Byte[] buffer=new byte[1024];
int cnt=s.Receive(buffer);
this.richTextBox1.Text=System.Text.Encoding.Default.GetString(buffer,0,cnt);
s.Close();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?