Answer the question
In order to leave comments, you need to log in
Why are messages not being received?
It works under winforms, but it doesn't.
public class MainActivity : Activity
{
public string mess;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
StartListening ();
Button bt = FindViewById<Button>(Resource.Id.button1);
bt.Click += delegate { start();};
// Get our button from the layout resource,
// and attach an event to it
}
public void start()
{
TextView text = FindViewById<TextView> (Resource.Id.textView1);
StartListening();
text.Text = mess;
//text.SetText (mess);
}
private readonly UdpClient udp = new UdpClient(45000);
public void StartListening()
{
this.udp.BeginReceive(Receive, new object());
}
public void Receive(IAsyncResult ar)
{
IPEndPoint ip = new IPEndPoint(IPAddress.Any, 45000);
byte[] bytes = udp.EndReceive(ar, ref ip);
mess = Encoding.ASCII.GetString(bytes);
StartListening();
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question