/// <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); }
/// <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); }
private void SendPacket(Message message) { UdpNetwork.SendData(JsonConvert.SerializeObject(message.packet), message.ipEndPoint); Debug.Log(message.packet.Header); }
private void OnDestroy() { DisconnectFromAll(); UdpNetwork.CloseConnection(); }