PolarListener.cs 597 B

123456789101112131415161718192021222324252627282930
  1. using System;
  2. using UnityEngine;
  3. public class PolarListener : MonoBehaviour
  4. {
  5. private UdpConnection connection;
  6. private void Start()
  7. {
  8. string sendIp = "127.0.0.1";
  9. int sendPort = 8881;
  10. int receivePort = 6789;
  11. connection = new UdpConnection();
  12. connection.StartConnection(sendIp, sendPort, receivePort);
  13. }
  14. private void Update()
  15. {
  16. foreach (var message in connection.getMessages()) Debug.Log(message);
  17. connection.Send("Hi!");
  18. }
  19. private void OnDestroy()
  20. {
  21. connection.Stop();
  22. }
  23. }