huangboxiID:huangboxi
278次访问,排名2万外好友0人,关注者0
huangboxi的文章
原创 3 篇
翻译 0 篇
转载 0 篇
评论 0 篇
最近评论
文章分类
收藏
    相册
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 使用UDP协议发送和接收数据收藏

    新一篇: C#读取DBF文件 | 

    首选引用以下两个:
    using System.Net;
    using System.Net.Sockets;

    //获取机机IP地址:
    IPHostEntry ihe = Dns.GetHostByName(Dns.GetHostName());
    IPAddress myself = ihe.AddressList[0];
    //发送消息
    UdpClient udpClient = new UdpClient(Ip地址,端口);
    Byte[] sendBytes = Encoding.UTF8.GetBytes("信息内容" );   
    udpClient.Send(sendBytes, sendBytes.Length);        //发送消息
    //侦听消息
    UdpClient receivingUdpClient = new UdpClient(侦听端口);
    IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
     while (true)         //循环扫描
    {
           try
           {
                Byte[] receiveBytes = receivingUdpClient.Receive(ref RemoteIpEndPoint);    //获取接受到的信息,传的时候是以Byte[]来传的,所以接受时也要用Byte
                  string stripaddress = RemoteIpEndPoint.Address.ToString();    //发送方IP地址
                   string strPort=RemoteIpEndPoint.Port.ToString();      //发送方端口
            }
    }

     

    发表于 @ 2008年05月12日 10:04:32|评论(loading...)|编辑

    新一篇: C#读取DBF文件 | 

    评论:没有评论。

    发表评论  


    当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
    Csdn Blog version 3.1a
    Copyright © huangboxi