且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用SSL / TLS保护我的套接字连接System.Net.Sockets.Socket

更新时间:2023-02-13 19:16:58

本文解释了System.Net命名空间中SSL的用法:

http://msdn.microsoft.com/en-us/library/ds8bxk2a%28v=vs.110%29.aspx [ ^ ]



这也是一个部分(左侧链接)以确定证书选择。



如果您在托管环境中,您的Web服务器软件可用于控制SSL的运行方式。如果是IIS,请查看绑定。
This article explains the usage of SSL in the System.Net namespace:
http://msdn.microsoft.com/en-us/library/ds8bxk2a%28v=vs.110%29.aspx[^]

The is also a section (linked on the left) to determine certificate selection.

If you are in a hosted environment, your web Server software can be used to control how SSL operates. If IIS, have a look at the bindings.


谢谢Nathan,



但在我的情况下,我没有使用WebRequest 。我有一个客户端服务器环境。

在服务器上,端口上运行窗口服务。和客户端我运行另一个窗口应用程序,通过调用类System.Net.Sockets.Sockets的Connect()方法创建套接字连接(套接字编程)。所以我想用SSL / TLS保护这个连接。我正在使用带有.net 3.5的visual studio 2008来装箱客户端应用程序和窗口服务。你可以参考下面的代码我如何在客户端和服务器之间建立连接。



Thanks Nathan,

But in my case I am not using the WebRequest. I have a client server environment.
On server there is window service running on a port. and client side I am running another window application that creates a socket connection (Socket Programming) by calling Connect() method of class System.Net.Sockets.Sockets. So I want to secure this connection with SSL/TLS. I am using visual studio 2008 with .net 3.5 for crating the client application and window service. You can refer the below code how I am creating a connection between client and server.

clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

               IPAddress remoteIp = IPAddress.Parse("Server IP");
               int serverPort = Convert.ToInt32("Server Port");
                IPEndPoint ipEnd = new IPEndPoint(remoteIp, serverPort);
               clientSocket.Connect(ipEnd);