这是发送端程序:
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
namespace UDPClient
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
private static IPAddress GroupAddress =
IPAddress.Parse("210.46.78.88");
private static int GroupPort = 11000; /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
Send();
Console.Read (); } private static void Send( )
{
UdpClient sender = new UdpClient();
IPEndPoint groupEP = new IPEndPoint(GroupAddress,GroupPort); try
{
Console.WriteLine ("input you message!");
string message = Console.ReadLine ();
Console.WriteLine("*******Sending datagram : {0}******", message);
byte[] bytes = Encoding.ASCII.GetBytes(message); sender.Send(bytes, bytes.Length, groupEP);
sender.Close();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
} }
}大家运行一下试试
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
namespace UDPClient
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
private static IPAddress GroupAddress =
IPAddress.Parse("210.46.78.88");
private static int GroupPort = 11000; /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
Send();
Console.Read (); } private static void Send( )
{
UdpClient sender = new UdpClient();
IPEndPoint groupEP = new IPEndPoint(GroupAddress,GroupPort); try
{
Console.WriteLine ("input you message!");
string message = Console.ReadLine ();
Console.WriteLine("*******Sending datagram : {0}******", message);
byte[] bytes = Encoding.ASCII.GetBytes(message); sender.Send(bytes, bytes.Length, groupEP);
sender.Close();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
} }
}大家运行一下试试
解决方案 »
- winfrom连接数据取值生成TXT文件
- javascript 如何在左框架里 取得右框架网页的网址?
- 想用c#编写串口,不知用哪种方法好?(初学者)
- 水晶报表筛选
- C#的类库到底怎么用啊~~~
- ListItem的问题
- 200分求:为什么我的pl/sql developer查询出来的中文全部变为“靠”
- 一个图像处理问题。把一幅图四周的黑色区域内的部分扩大到原图大小,100分。
- 求助,高手来!(在线等)
- 多个网站,一个服务器一个网站,共用一个数据库。求一个稳定的方案。
- 为何Web Service接口得不到传递过来的参数值(c#)?
- 超级难题,测测程序员们的智商,12个形状相同的球,其中有一个质量与其他球不一样,请用一架天平3次把它称出来。
getByteLen = sockServer.Receive(recvBytes,recvBytes.Length,0); if (getByteLen != 0){
....
}
你的:
listener.Connect(groupEP);
byte[] bytes = listener.Receive( ref groupEP);
乃病句也