频道栏目
首页 > 资讯 > C# > 正文

高性能异步Socket服务器(UDP)

10-07-11        来源:[db:作者]  
收藏   我要投稿

采用异步模式设计的UDP服务器,源码如下:

 

1 using System;
2  using System.Net;
3  using System.Net.Sockets;
4 using System.ServiceProcess;
5 using System.Threading;
6
7 namespace TestUdpServer
8 {
9 // this class encapsulates a single packet that
10 // is either sent or received by a UDP socket
11 public class UDPPacketBuffer
12 {
13 // size of the buffer
14 public const int BUFFER_SIZE = 4096;
15
16 // the buffer itself
17 public byte[] Data;
18
19 // length of data to transmit
20 public int DataLength;
21
22 // the (IP)Endpoint of the remote host
23 public EndPoint RemoteEndPoint;
24
25 public UDPPacketBuffer()
26 {
27 this.Data = new byte[BUFFER_SIZE];
28
29 // this will be filled in by the call to udpSocket.BeginReceiveFrom
30 RemoteEndPoint = (EndPoint)new IPEndPoint(IPAddress.Any, 0);
31 }
32
33 public UDPPacketBuffer(byte[] data, EndPoint remoteEndPoint)
34 {
35 this.Data = data;
36 this.DataLength = data.Length;
37 this.RemoteEndPoint = remoteEndPoint;
38 }
39 }
40
41 public abstract class UDPServer
42 {
相关TAG标签
上一篇:C#实现所有经典排序算法
下一篇:10进制转换与括号匹配算法
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站