我使用这个代码C#如何知道是否发送UDP数据包?
bool NotSent = true;
while (NotSent)
{
try
{
UdpClient udpServer = new UdpClient(port);
udpServer.Connect(IPAddress.Parse("192.168.1.66"), port);
Byte[] sendBytes = Encoding.ASCII.GetBytes("Hello");
int res = udpServer.Send(sendBytes, sendBytes.Length);
MessageBox.Show("Sent : " + res);
udpServer.Close();
NotSent = false;
}
catch (Exception ex) { MessageBox.Show("Error : " + ex.ToString()); continue; }
}
,所以我怎么知道“你好”发送和接收与否,因为所有的结果通常会返回17
现在明白了,谢谢彼得 –