使用Chilkat搭建的.NET平台的SSL Socket服务器

手册:http://www.chilkatsoft.com/refdoc/csSocketRef.html

Chilkat.Socket Listen = new Chilkat.Socket();

bool SUCCESS;

SUCCESS = Listen.UnlockComponent("Anything for 30-day trial");//解锁

if (!SUCCESS) { MessageBox.Show("Unlock Failed!"); }



Chilkat.CertStore CertStore = new Chilkat.CertStore();

SUCCESS = CertStore.LoadPfxFile("1.pfx", "1");//加载证书

if (!SUCCESS) { MessageBox.Show("Load CertStore Failed!"); }

Chilkat.Cert Cert = null;

Cert = CertStore.FindCertBySubject("F1sher-PC");

if (Cert == null) { MessageBox.Show("Find Cert Failed!"); }



SUCCESS = Listen.InitSslServer(Cert);//初始化SSL服务器

if (!SUCCESS) { MessageBox.Show("Init SSLServ Failed!"); }



SUCCESS = Listen.BindAndListen(8080, 5);

if (!SUCCESS) { MessageBox.Show(Listen.LastErrorText); }



Listen.MaxReadIdleMs = 10000;

Listen.MaxSendIdleMs = 10000;



while (true)

{

	Chilkat.Socket Client = null;

	Client = Listen.AcceptNextConnection(0);

	if (Client != null)

	{

		string recv = Client.ReceiveString();

		if (recv != "")

		{

			LogRichTB.AppendText("Revevied:\n" + recv + "\n");

			string send = "HaHa";

			Client.SendString(send);

		}

		Client.Close(1000);

	}

}

  

你可能感兴趣的:(socket)