/// <summary> /// Send data through an UDPChannel to a distant user and returns an <see cref="UDPDataInfo"/> object.</summary> /// <param name='channelName'>The name of the channel you want to send your message through.</param> /// <c>It must be registered on this instance, if a channel with that name can't be found the method will throw an exception!</c> /// <remarks>You can check if the name is registered by calling <see cref="GetChannelByName"/></remarks> /// <param name="udpData">A <see cref="JavaScriptObject"/> that contains the data to send</param> /// <param name="remoteAddress">The IPV4 address of the target</param> /// <param name="remotePort">The port of the target</param> public UDPDataInfo Send(string channelName, object udpData, string remoteAddress, int remotePort) { UDPChannel channel; if (channelName == UDPManager._UDPMRCP) { channel = this._pingChannel; } else if (channelName == UDPManager._UDPMRCC) { channel = this._connectionChannel; } else if (channelName.Length >= 8 && channelName.Substring(0, 8) == UDPManager._UDPMRCP + ":") { channel = this._GetHiddenClientPingChannelByID(channelName.Split(':')[1]); } else { channel = this.GetChannelByName(channelName); } //console.log("SEND ",udpData.messageType,"TO",channelName,remoteAddress,remotePort); if (channel != null) { UDPDataInfo udpDataInf = new UDPDataInfo(channelName, remoteAddress, remotePort, udpData, this._GetNextUniqueID()); channel._AddDataToBuffer(udpDataInf); return(udpDataInf); } else { throw new ArgumentNullException("Channel :" + channelName + " not registered, use addChannel method first"); } }
internal void _AddDataToBuffer(UDPDataInfo dataInfo) { _dataBuffer.Add(dataInfo); if (!_running) { _SendNextData(); //if there is no message currently being sent start the sending again } }