Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement