最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
WPF实现Socket异步通讯示例
时间:2022-06-25 08:42:49 编辑:袖梨 来源:一聚教程网
示例一
代码如下 | 复制代码 |
public class SocketHelper
|
三种方式实现异步socket
代码如下 | 复制代码 |
using System; namespace ExtensionTest public class NetWork private IPEndPoint endPoint; public NetWork() server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); public void StartListening() public void StartListeningWithIterator() private void AcceptCallback(IAsyncResult asyncResult) byte[] buffer = new byte[256]; receiveSocket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, ReceiveCallback, new State(receiveSocket, buffer)); // private void ReceiveCallback(IAsyncResult asyncResult) if (state != null) private void SendCallback(IAsyncResult asyncResult) private IEnumerator yield return 1; Socket receiveSocket = server.EndAccept(enumerator.DequeueAsyncResult()); byte[] buffer = new byte[256]; receiveSocket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, enumerator.End(), null); yield return 1; int receLength = receiveSocket.EndReceive(enumerator.DequeueAsyncResult()); if (receLength > 0) yield return 1; receiveSocket.EndSend(enumerator.DequeueAsyncResult()); private void StartAsync(Socket socket) byte[] buffer = new byte[256]; if (receLength > 0) };
private class State public State(Socket socket, byte[] bytes) |
相关文章
- 《无限暖暖》织衣蛛获得方法 12-26
- 《无限暖暖》美食家蜜蜂获得方法 12-26
- 《无限暖暖》泳镜蝽获得方法 12-26
- 《无限暖暖》芭蕾豆娘获得方法 12-26
- 《无限暖暖》刺绣蛾获得方法 12-26
- 《无限暖暖》尖帽仙获得方法 12-26