A
A
akass2015-03-11 22:30:11
Android
akass, 2015-03-11 22:30:11

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();
 
    }
}
    }

In the future, I want to not catch one at a time, but somehow display everything, but I won’t get to that if the message is not received / displayed at this stage already.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question