参考:http://www.cnblogs.com/sunev/archive/2012/08/08/2627247.html
原文代码这里贴一份------------------------------------------------------------------>
server:
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
namespace server
{
class Program
{
static void Main(string[] args)
{
int recv;
byte[] data = new byte[1024];
//得到本机IP,设置TCP端口号
IPEndPoint ip = new IPEndPoint(IPAddress.Any, 8001);
Socket newsock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
//绑定网络地址
newsock.Bind(ip);
Console.WriteLine("This is a Server, host name is {0}", Dns.GetHostName());
//等待客户机连接
Console.WriteLine("Waiting for a

本文介绍了如何使用 C# 实现基于 UDP 的通信,重点在于建立心跳程序,以便多个设备能向服务器发送状态信息。选择 UDP 而不是 TCP 是因为 UDP 在速度和一对多通信上的优势。

7291

被折叠的 条评论
为什么被折叠?



