|
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Net;
- using System.Net.Sockets;
- namespace cejie
- {
- class Program
- {
- static void Main(string[] args)
- {
- //Creates a UdpClient for reading incoming data.
- UdpClient receivingUdpClient = new UdpClient(2950);
- //Creates an IPEndPoint to record the IP Address and port number of the sender.
- // The IPEndPoint will allow you to read datagrams sent from any source.
- //IPAddress ip = new IPAddress("192.168.137.115");
- IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
- while (true)
- {
- // Blocks until a message returns on this socket from a remote host.
- Byte[] receiveBytes = receivingUdpClient.Receive(ref RemoteIpEndPoint);
- //string returnData = Encoding.ASCII.GetString(receiveBytes);
- //Console.WriteLine("This is the message you received " +
- // returnData.ToString());
- Console.WriteLine("This message was sent from " +
- RemoteIpEndPoint.Address.ToString() +
- " on their port number " +
- RemoteIpEndPoint.Port.ToString());
- }
- }
- }
- }
- //在pc机上运行没有什么问题。能接受到发送的数据。但是放到wince上边怎么出错啊?说什么少什么程序集。想知道到底是程序有问题还是装的wince有问题??
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Net;
- using System.Net.Sockets;
- using System.Threading;
- namespace jieshou
- {
- class Program
- {
- static void Main(string[] args)
- {
- Jie();
- }
- static void Jie()
- {
- int i = 0;
- Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);//初始化一个Scoket协议
- IPEndPoint iep = new IPEndPoint(IPAddress.Any, 3000);//初始化一个侦听局域网内部所有IP和指定端口
- EndPoint ep = (EndPoint)iep;
- socket.Bind(iep);//绑定这个实例
- while (true)
- {
- byte[] buffer = new byte[1024];//设置缓冲数据流
- socket.ReceiveFrom(buffer, ref ep);//接收数据,并确把数据设置到缓冲流里面
- Console.WriteLine(Encoding.Unicode.GetString(buffer).TrimEnd('\u0000') + " " + i.ToString());
- i++;
- }
- }
- }
- }
- //又写了一个socket的接收程序。在pc上边运行没问题。但放到wince上边就没法跑。程序运行的时候出错。说是缺少程序集。socket.net.bind();不知道问题出在哪??而且发生了奇怪的事情,前边这两个程序自己运行过。能成功。但是不正常,不知道那的原因??
复制代码
|
|