Advertisement
akass

Untitled

Mar 3rd, 2015
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. public class MainActivity : Activity
  2. {
  3.     public string mess;
  4.  
  5.     protected override void OnCreate (Bundle bundle)
  6.     {
  7.         base.OnCreate (bundle);
  8.  
  9.         // Set our view from the "main" layout resource
  10.         SetContentView (Resource.Layout.Main);
  11.         StartListening ();
  12.  
  13.  
  14.         Button bt = FindViewById<Button>(Resource.Id.button1);
  15.         bt.Click += delegate { start();};
  16.         // Get our button from the layout resource,
  17.         // and attach an event to it
  18.         }
  19.     public void start()
  20.     {
  21.         TextView text = FindViewById<TextView> (Resource.Id.textView1);
  22.  
  23.  
  24.         StartListening();
  25.         text.Text = mess;
  26.         //text.SetText (mess);
  27.     }
  28.     private readonly UdpClient udp = new UdpClient(45000);
  29.  
  30.     public void StartListening()
  31.     {
  32.         this.udp.BeginReceive(Receive, new object());
  33.  
  34.  
  35.  
  36.  
  37.     }
  38.     public void Receive(IAsyncResult ar)
  39.     {
  40.         IPEndPoint ip = new IPEndPoint(IPAddress.Any, 45000);
  41.         byte[] bytes = udp.EndReceive(ar, ref ip);
  42.  
  43.  
  44.         mess = Encoding.ASCII.GetString(bytes);
  45.         StartListening();
  46.  
  47.     }
  48. }
  49.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement