UDPBroadcast.cs 779 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using LitJson;
  2. using System.Net;
  3. using System.Net.Sockets;
  4. using Unity.RenderStreaming;
  5. using Unity.RenderStreaming.Signaling;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. public class UDPBroadcast : MonoBehaviour
  9. {
  10. private UdpClient udpClient;
  11. private IPEndPoint ipEndPoint;
  12. void Start()
  13. {
  14. udpClient = new UdpClient();
  15. ipEndPoint = new IPEndPoint(IPAddress.Parse("255.255.255.255"), 1234);
  16. }
  17. void Update()
  18. {
  19. SendData();
  20. }
  21. public Camera ca;
  22. public Text t;
  23. void SendData()
  24. {
  25. string message = "hello World";
  26. byte[] data2 = System.Text.Encoding.ASCII.GetBytes(message);
  27. udpClient.Send(data2, data2.Length, ipEndPoint);
  28. }
  29. void OnDestroy()
  30. {
  31. udpClient.Close();
  32. }
  33. }