コード例 #1
0
    /// <summary>
    /// 开始udp监听
    /// </summary>
    public void StartListening()
    {
        if (isRunning)
        {
            return;
        }
        isRunning = true;

        socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
        udpSendSocket.IniSocket(socket, ConfigManager.ServerIP, ConfigManager.ServerPort);
        udpReceiveSocket.InitSocket(socket, ConfigManager.ServerIP, ConfigManager.ServerPort);
        udpReceiveSocket.OnReceiveData += OnReceiveData;

        Debug.Log("Start listening");
        StartCoroutine(SendHeart());

        udpHeratTime = DateTime.Now;
    }
コード例 #2
0
    /// <summary>
    /// 开始udp监听
    /// </summary>
    public void StartListening()
    {
        if (isRunning)
        {
            return;
        }
        isRunning = true;

#if !UNITY_EDITOR && UNITY_WSA
        upClient.Connect(Config._instance.ChatStreamServerIP, Config._instance.ChatStreamServerPort);
        upClient.OnReceiveData += OnReceiveData;
#else
        socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
        udpSendSocket.IniSocket(socket, Config.Instance.ChatStreamServerIP, Config.Instance.ChatStreamServerPort);
        udpReceiveSocket.InitSocket(socket, Config.Instance.ChatStreamServerIP, Config.Instance.ChatStreamServerPort);
        udpReceiveSocket.OnReceiveData += OnReceiveData;
#endif
        print("Start listening");
        StartCoroutine(sendHeart());

        udpHeratTime = DateTime.Now;
    }