public override bool SendData(byte[] bytes, int size, Topic t) { bool result = true; if (this.topicSinkMap.ContainsKey(t.GetName())) { Entry_T dict = this.topicSinkMap[t.GetName()]; List <string> sinksToDelete = new List <string>(); // Loop over all sinks and send data, remove items that isn't "alive". foreach (KeyValuePair <string, IpPortPair> kvp in dict.portMap) { // Check if this sink is alive if (kvp.Value.IsAlive()) { result &= SendData(bytes, size, InetAddress.GetByName(kvp.Value.Ip), kvp.Value.Port); } else //Remove it. { sinksToDelete.Add(kvp.Key); } } foreach (string key in sinksToDelete) { dict.portMap.Remove(key); } } return(result); }
public bool SendTo(byte[] bytes, int offset, int size, string ip, int port) { try { return(this.SendTo(bytes, offset, size, InetAddress.GetByName(ip), port)); } catch (Exception) { return(false); } }
public bool SendTo(byte[] bytes, int offset, int size, string ip, int port) { try { return(SendTo(bytes, offset, size, InetAddress.GetByName(ip), port)); } catch (Exception ex) { Logger.ExceptionLogger.LogException(ex); return(false); } }
/// Protection is not needed since all calls go through the participant which is synched public ReceiveDataHandler GetReceiveDataHandler(Topic top, Participant participant) { // In the case that we use the same port for several topics, we need to find the receiver for the transport::address::port used string key = MakeKey(top); if (ReceiveDataHandlers.ContainsKey(key)) { ReceiveDataHandler rdh = ReceiveDataHandlers[key]; // Check if any of the topics have a sample size larger than MAX_SEGMENT_SIZE // This will lead to a problem when using the same port, if samples becomes > MAX_SEGMENT_SIZE if ((rdh.GetSampleMaxSize() > Globals.MAX_SEGMENT_SIZE) || (top.GetSampleMaxSize() > Globals.MAX_SEGMENT_SIZE)) { if (top.GetTransport().Equals(Topic.TRANSPORT_UDP)) { Logger.ExceptionLogger.LogMessage("Warning: UDP transport is used with Topics with 'sampleMaxSize' > " + Globals.MAX_SEGMENT_SIZE); } else { Logger.ExceptionLogger.LogMessage("Warning: Same port (" + top.GetPort() + ") is used with Topics with 'sampleMaxSize' > " + Globals.MAX_SEGMENT_SIZE); } } return(rdh); } // Get the local interface, doing a translation from subnet if necessary string localIF = InetAddress.DoSubnetTranslation(top.GetLocalInterface()); // Didn't exist, create one if transport is known if ((top.GetTransport().Equals(Topic.TRANSPORT_MC)) || (top.GetTransport().Equals(Topic.TRANSPORT_TCP))) { ReceiveDataHandlers.Add(key, new ReceiveDataHandler(top, participant, ReceiverFactory.CreateReceiver(top, localIF))); return(ReceiveDataHandlers[key]); } else if (top.GetTransport().Equals(Topic.TRANSPORT_UDP)) { IReceiver rec = ReceiverFactory.CreateReceiver(top, localIF); ReceiveDataHandlers.Add(key, new ReceiveDataHandler(top, participant, rec)); if (key.Equals(Topic.TRANSPORT_UDP)) { participant.SetUdpTransportInfo(((UdpReceiver)rec).IP, ((UdpReceiver)rec).Port); } return(ReceiveDataHandlers[key]); } return(null); }
///LA TODO Protection ?? What if several subscribers at the same time /// Not needed since all calls go through the participant which is synched public ISendDataHandler GetSendDataHandler(Topic t, Participant participant) { // Get the local interface, doing a translation from subnet if necessary string localIF = InetAddress.DoSubnetTranslation(t.GetLocalInterface()); string key = MakeKey(t, localIF); if (SendDataHandlers.ContainsKey(key)) { ISendDataHandler sender = SendDataHandlers[key]; if (t.GetTransport().Equals(Topic.TRANSPORT_UDP)) { PostSetup(t, participant, (McUdpSendDataHandler)sender); } return(sender); } try { ISendDataHandler sender = null; if (t.GetTransport().Equals(Topic.TRANSPORT_MC)) { sender = new McSendDataHandler(t, localIF, t.GetTimeToLive()); } else if (t.GetTransport().Equals(Topic.TRANSPORT_TCP)) { sender = new TcpSendDataHandler(t, localIF); } else if (t.GetTransport().Equals(Topic.TRANSPORT_UDP)) { // We have only one sender for all topics on an interface, so use the domain value for buffer size sender = new McUdpSendDataHandler(participant.getDomain().GetOutSocketBufferSize(), localIF); PostSetup(t, participant, (McUdpSendDataHandler)sender); } if (sender != null) { SendDataHandlers.Add(key, sender); return(sender); } throw new CommException("No such Transport " + t.GetTransport()); } catch (System.IO.IOException ex) { throw new CommException("Error creating SendDataHandler. IOException -->" + ex.Message); } }
public bool SendTo(byte[] bytes, int offset, int size, InetAddress ipAddress, int port) { try { IPEndPoint ipep = new IPEndPoint(ipAddress.GetIPAddress(), port); // "UdpClient" do not include a send method with an offset. // Hence we must use the underlaying socket "Client" to be able to // send a byte buffer starting with an offset multicastSocket.Client.SendTo(bytes, offset, size, SocketFlags.None, (EndPoint)ipep); return(true); } catch (Exception) { return(false); } }
// Return true if a valid node address public static bool IsValidNodeAddress(string addr) { try { InetAddress ad = new InetAddress(addr); ulong Ip = ad.ToNum(); if (Ip == 0) { return(false); } if (Ip >= 0xE0000000) { return(false); // Skip multicast and above } return(true); } catch { return(false); } }
protected bool SendData(byte[] bytes, int size, InetAddress ip, int port) { int nrSegmentsNeeded = (int)(size / Globals.MAX_SEGMENT_SIZE); if (size % Globals.MAX_SEGMENT_SIZE != 0) { nrSegmentsNeeded++; } for (int i = 0; i < nrSegmentsNeeded; i++) { //If this is the last element, only send the bytes that remains, otherwise send a full package. int sizeToSend = (i == nrSegmentsNeeded - 1) ? size - (nrSegmentsNeeded - 1) * Globals.MAX_SEGMENT_SIZE : Globals.MAX_SEGMENT_SIZE; if (!sender.SendTo(bytes, i * Globals.MAX_SEGMENT_SIZE, sizeToSend, ip, port)) { return(false); } } return(true); }
public static bool IsMyNodeAddress(String addr) { try { InetAddress nodeaddr = new InetAddress(addr); if (nodeaddr.IsAnyLocalAddress()) { return(true); } System.Net.NetworkInformation.NetworkInterface[] nics = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces(); if (nics != null && nics.Length > 0) { foreach (System.Net.NetworkInformation.NetworkInterface adapter in nics) { System.Net.NetworkInformation.IPInterfaceProperties properties = adapter.GetIPProperties(); System.Net.NetworkInformation.UnicastIPAddressInformationCollection uniCast = properties.UnicastAddresses; if (uniCast == null) { continue; } foreach (System.Net.NetworkInformation.UnicastIPAddressInformation uni in uniCast) { if (uni.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) //IPV4 { if (nodeaddr.Equals(uni.Address)) { return(true); } } } } } return(false); } catch { return(false); } }
public McSendDataHandler(Topic t, string localInterface) { sender = new MulticastSender(0, localInterface, 1, t.GetOutSocketBufferSize()); // Make ttl configurable sinkIP = InetAddress.GetByName(t.GetDomainAddress()); }
public bool Equals(InetAddress addr) { return(this.addr.ToString().Equals(addr.ToString())); }
public TcpSendDataHandler(Topic t, string localInterface) { sender = new TcpServerSender(t.GetDomainAddress(), t.GetPort(), t.GetOutSocketBufferSize()); sinkIP = InetAddress.GetByName(t.GetDomainAddress()); }
public bool SendTo(byte[] bytes, int offset, int size, InetAddress ipAddress, int port) { return(tcpSenderList.SendTo(bytes, offset, size, ipAddress, port)); }
public McSendDataHandler(Topic t, string localInterface, int ttl) { sender = new MulticastSender(0, localInterface, ttl, t.GetOutSocketBufferSize()); sinkIP = InetAddress.GetByName(t.GetDomainAddress()); }
// Synchronization is unnecessary since the code only calls a synchronized method public bool SendTo(byte[] bytes, int offset, int size, InetAddress ipAddress, int port) { return(this.SendTo(bytes, offset, size, ipAddress.GetHostAddress(), port)); }