I'm busy making an webbased udp communications application for communication with a hardware solution, for now everything works fine the messages i send from my webform arriving at the terminal and the terminals is responding. I can see the udp packages because i've installed ethereal.
Now i want the reply message from the udp message i send be placed in a label txtPing, below is my source code but how can i realize this.
public
{
private const int listenPort = 2002; private static void StartListener(){
UdpClient listener = new UdpClient(listenPort); IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, listenPort); try{
byte[] bytes = listener.Receive(ref groupEP); Console.WriteLine("Received broadcast from {0} :\n {1}\n",groupEP.ToString(),
Encoding.ASCII.GetString(bytes, 0, bytes.Length));}
catch (Exception e){
Console.WriteLine(e.ToString());}
}
}
public
partial class _Default : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
}
protected void Button1_Click(object sender, EventArgs e){
string ip = Ipadres1.Text; string Poort = Poort1.Text; int SendPoort = Convert.ToInt32(Poort); UdpClient udpClient = new UdpClient(); // Bericht verzenden. Byte[] sendBytes = Encoding.ASCII.GetBytes(Command1.Text + (char)13); try{
udpClient.Send(sendBytes, sendBytes.Length, ip, SendPoort);
}
catch (Exception error){
Console.WriteLine(error.ToString());}
}
protected void Button2_Click(object sender, EventArgs e)
{
string ip = Ipadres1.Text;lblStatus.Text =
null;txtPing.Text =
null; try{
Ping ping = new Ping(); PingReply pingreply = ping.Send(Ipadres1.Text);txtPing.Text +=
"Ip adres : " + pingreply.Address + "\r
";
txtPing.Text +=
" Tijd : " + pingreply.RoundtripTime + " ms \r";
txtPing.Text +=
" TTL (Time To Live): " + pingreply.Options.Ttl + " ms \r";
txtPing.Text +=
" Buffer Size: " + pingreply.Buffer.Length.ToString() + " bytes \r";}
catch (Exception err){
lblStatus.Text = err.Message;
}
}
}
Replies
Know the answer? Post it — somebody with the same question will find it here.