| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- using System.Collections;
- using System.Collections.Generic;
- using System.Net;
- using System.Net.Sockets;
- using UnityEngine;
- public class Demo : MonoBehaviour
- {
- private void Start()
- {
- LuaSocketManager.Connect("192.168.1.85", 9305);
- StartCoroutine(SendLoop());
- StartCoroutine(ReceiveLoop());
- }
- private void OnDestroy()
- {
- LuaSocketManager.Disconnect();
- }
- IEnumerator SendLoop()
- {
- while (enabled)
- {
- Debug.Log("Demo Send");
- LuaSocketManager.Send(@"{ ""msgType"":""HEARTBEAT"", ""uid"":""cc187cd3-f36d-4b8a-9500-1f826e709b5d"" }");
- yield return new WaitForSeconds(1f);
- }
- }
- IEnumerator ReceiveLoop()
- {
- while (enabled)
- {
- yield return new WaitForSeconds(.1f);
- string msg = LuaSocketManager.RecvMessage();
- if (msg != null)
- {
- Debug.Log($"Demo Recv: {msg}");
- }
- }
- }
- }
|