Socket 代码示例Socket Code Examples

以下代码示例演示如何使用 Socket 类作为客户端连接到远程网络服务,以及如何将它用作服务器以侦听来自远程客户端的连接。The following code examples demonstrate how to use the Socket class as a client to connect to remote network services and as a server to listen for connections from remote clients.

本节内容In This Section

同步客户端套接字示例Synchronous Client Socket Example
演示如何实现连接到服务器的同步 Socket 客户端,并显示从服务器返回的数据。Shows how to implement a synchronous Socket client that connects to a server and displays the data returned from the server.

同步服务器套接字示例Synchronous Server Socket Example
演示如何实现接受客户端连接的同步 Socket 服务器,并回传从客户端收到的数据。Shows how to implement a synchronous Socket server that accepts connections from a client and echoes back the data received from the client.

异步客户端套接字示例Asynchronous Client Socket Example
演示如何实现连接到服务器的同步 Socket 客户端,并显示从服务器返回的数据。Shows how to implement an asynchronous Socket client that connects to a server and displays the data returned from the server.

异步服务器套接字示例Asynchronous Server Socket Example
演示如何实现接受客户端连接的同步 Socket 服务器,并回传从客户端收到的数据。Shows how to implement an asynchronous Socket server that accepts connections from a client and echoes back the data received from the client.

套接字Sockets
提供有关 System.Net.Sockets 命名空间和 Socket 类的基本信息。Provides basic information about the System.Net.Sockets namespace and the Socket class.

网络编程中的安全性Security in Network Programming
描述如何使用 Internet 标准安全性和身份验证方法。Describes how to use standard Internet security and authentication techniques.