Пример #1
0
        /// <summary>
        /// Ask signaling server to register current device's public ip address on connectable peer list.<br/>
        /// </summary>
        public void RequestHandshake()
        {
            Debug.LogWarning("requesting handshake.");

            IPPair thisIP = new IPPair(UdpNetwork.GetLocalAddress(), null, 0);

            DataPacket packet = new DataPacket(Header.request_handshake, JsonConvert.SerializeObject(thisIP));

            SendRequest(new Message(packet, signalingServer), Header.response_handshake);
        }
Пример #2
0
        /// <summary>
        /// Sends customized string to peer.
        /// </summary>
        public void SendCustomMessage(string customMessage)
        {
            if (networkConnectionState.Value != ConnectionState.publicPeer && networkConnectionState.Value != ConnectionState.localPeer)
            {
                return;
            }

            IPEndPoint endPoint = (networkConnectionState.Value == ConnectionState.publicPeer) ? peerIP.GetPublicIPEndPoint() : peerIP.GetLocalIPEndPoint();

            DataPacket packet = new DataPacket(Header.custom_message, customMessage);

            UdpNetwork.SendData(JsonConvert.SerializeObject(packet), endPoint);
        }
Пример #3
0
        private void SendPacket(Message message)
        {
            UdpNetwork.SendData(JsonConvert.SerializeObject(message.packet), message.ipEndPoint);

            Debug.Log(message.packet.Header);
        }
Пример #4
0
 private void OnDestroy()
 {
     DisconnectFromAll();
     UdpNetwork.CloseConnection();
 }