Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DatagramSocket socket = new DatagramSocket(5001);
- public void Recive()
- {
- WifiManager wifi = (WifiManager)ApplicationContext.GetSystemService(Context.WifiService);
- Android.Net.Wifi.WifiManager.MulticastLock multicastLock = wifi.CreateMulticastLock("MediaPlayer");
- if (multicastLock != null)
- {
- multicastLock.Acquire();
- }
- Android.Net.Wifi.WifiManager.WifiLock castLock = wifi.CreateWifiLock("MediaPlayer");
- if (castLock != null)
- {
- castLock.Acquire();
- }
- Task.Run(async () =>
- {
- socket.Broadcast = true;
- byte[] buf = new byte[1024];
- DatagramPacket packet = new DatagramPacket(buf, buf.Length);
- LinearLayout parent = (LinearLayout)FindViewById(Resource.Id.chat);
- View view = LayoutInflater.Inflate(Resource.Layout.Opponent, parent, false);
- while (true)
- {
- await socket.ReceiveAsync(packet);
- if (packet.GetData() != null)
- {
- message mess = new message(packet);
- view.FindViewById<TextView>(Resource.Id.nick).Text = (string)mess.nick;//"Opponent";
- view.FindViewById<TextView>(Resource.Id.message).Text = (string)mess.mess;
- parent.AddView(view);
- }
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement