C# SOCKET 问题
高手请看下面的代码为什么不能执行啊?会报出参数有误的错误
这可是从MSDN里copy出来的
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
IPHostEntry lipa = Dns.Resolve("localhost");
IPEndPoint lep = new IPEndPoint(lipa.AddressList[0], 5151);
Socket s = new Socket(lep.Address.AddressFamily,
SocketType.Dgram,
ProtocolType.Udp);
try
{
// Creates an IpEndPoint to capture the identity of the sending host.
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
EndPoint tempRemoteEP = (EndPoint)sender;
// Creates a byte buffer to receive the message.
byte[] buffer = new byte[1024];
// Receives datagram from a remote host. This call blocks.
s.ReceiveFrom(buffer,0,100,SocketFlags.None, ref tempRemoteEP);
// Displays the information received to the screen.
Console.WriteLine(" I received the following message : " +
Encoding.ASCII.GetString(buffer) );
}
catch(Exception e)
{
Console.WriteLine("Exception : " + e.ToString() );
}
}
这可是从MSDN里copy出来的
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
IPHostEntry lipa = Dns.Resolve("localhost");
IPEndPoint lep = new IPEndPoint(lipa.AddressList[0], 5151);
Socket s = new Socket(lep.Address.AddressFamily,
SocketType.Dgram,
ProtocolType.Udp);
try
{
// Creates an IpEndPoint to capture the identity of the sending host.
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
EndPoint tempRemoteEP = (EndPoint)sender;
// Creates a byte buffer to receive the message.
byte[] buffer = new byte[1024];
// Receives datagram from a remote host. This call blocks.
s.ReceiveFrom(buffer,0,100,SocketFlags.None, ref tempRemoteEP);
// Displays the information received to the screen.
Console.WriteLine(" I received the following message : " +
Encoding.ASCII.GetString(buffer) );
}
catch(Exception e)
{
Console.WriteLine("Exception : " + e.ToString() );
}
}
...全文
相关推荐
C# Socket 聊天程序 文件传输有问题 望高手指教
在C#中,Socket编程是网络通信的基础,用于创建客户端和服务器端的连接,实现数据的交换。在本文中,我们将深入探讨如何使用C# Socket实现一个简单的聊天室程序,并着重解决文件传输的问题。
c# socket Server/Client 解决消息边界问题
这就是所谓的消息边界问题。标题中提到的"C# Socket Server/Client 解决消息边界问题"主要涉及以下技术点:1.
java Socket与C#通信中中文乱码问题的解决方案
在Java和C#之间进行Socket通信时,遇到中文乱码问题主要是由于编码格式不一致导致的。Java默认使用UTF-8编码,而C#在处理字符串时可能使用其他编码,如GBK或ASCII。
C# Socket通讯常见问题详解
C# Socket通信三大问题之数据包界限符问题。 根据原项目中交通部标准,在连续观测站中数据包中,使用??两个字符表示有效数据包开始和结束。实际项目有各自的具体技术规范 C# Socket通信三
Java和C#之间SOCKET通信的问题
"Java与C#之间的SOCKET通信涉及到网络编程中的异构系统间的数据交换。此问题描述了一个Java服务器端程序,它使用了`ServerSocket`来监听客户端的连接请求,通过`Executor


