谁能帮忙写一个C#调用hpsocket.net的例子啊求求了
TCP服务端能正常连接,但是SSL服务端连接怎么都有问题,连接进入马上就断开了,错误代码13using System;
using System.Threading.Tasks;
using HPSocket;
using HPSocket.Ssl;
using HPSocket.Tcp;
namespace SslServerDemo
{
class Program
{
static void Main(string[] args)
{
// 创建SSL服务端
//var server = new SslServer();
ISslServer server = new SslServer();
// 设置证书和私钥
server.Initialize(false);
server.VerifyMode = SslVerifyMode.None;
server.PemCertFile = "D:/cxiapu/zs/server.crt";
server.PemKeyFile = "D:/cxiapu/zs/server.key";
server.KeyPassword = "mwyfeeq568";
server.CaPemCertFileOrPath = "D:/cxiapu/zs/ca.crt";
//server.AddContext(SslVerifyMode.None, "D:/cxiapu/zs/server.crt", "D:/cxiapu/zs/server.key", "mwyfeeq568", "D:/cxiapu/zs/ca.crt");
server.Address = "0.0.0.0";
server.Port = 5001;
// 启动服务端
Console.WriteLine(server.Start());
Console.WriteLine("SSL服务启动 127.0.0.1:5001");
// 设置事件回调
server.OnSend += (sender, connId, data) =>
{
Console.WriteLine("发送事件");
return (0);
};
server.OnHandShake += (sender, connId) =>
{
Console.WriteLine($"握手事件");
return (0);
};
server.OnAccept += (sender, connId, client) =>
{
Console.WriteLine($"客户进入: {connId}");
// 发送欢迎消息给客户端
//server.Send(connId, "Welcome to SSL server!");
return (0);
};
server.OnReceive += (sender, connId, data) =>
{
Console.WriteLine($"数据到达: {connId}, data: {data}");
return (0);
};
server.OnClose += (sender, connId, operation, errorCode) =>
{
Console.WriteLine($"客户断开:{connId}错误代码:{errorCode}");
return (0);
};
// 等待客户端连接并收发数据
Console.ReadKey();
// 停止服务端
server.Stop();
}
}
}
页:
[1]