我使用這個代碼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
現在明白了,謝謝彼得 –