public static IReceiver CreateReceiver(Topic topic, String localInterface) { try { if (topic.GetTransport().Equals(Topic.TRANSPORT_MC)) { return(new MulticastReceiver(topic.GetDomainAddress(), topic.GetPort(), localInterface, topic.GetInSocketBufferSize())); } else if (topic.GetTransport().Equals(Topic.TRANSPORT_TCP)) { return(new TcpClientReceiver(topic.GetDomainAddress(), topic.GetPort(), topic.GetInSocketBufferSize())); } else if (topic.GetTransport().Equals(Topic.TRANSPORT_UDP)) { if (Ops.InetAddress.IsMyNodeAddress(topic.GetDomainAddress())) { // If UDP topic is configured with my node address, we use the configured port, otherwise // we use port 0 which will force the OS to create a unique port that we listen to. return(new UdpReceiver(topic.GetPort(), topic.GetDomainAddress(), topic.GetInSocketBufferSize())); } else { return(new UdpReceiver(0, localInterface, topic.GetInSocketBufferSize())); } } } catch (System.IO.IOException ex) { Logger.ExceptionLogger.LogMessage("CreateReceiver " + ex.ToString()); } 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) { // In the case that we use the same port for several topics, we need to find the sender for the transport::address::port used string key = t.GetTransport() + "::" + t.GetDomainAddress() + "::" + t.GetPort(); if (SendDataHandlers.ContainsKey(key)) { return(SendDataHandlers[key]); } try { // Get the local interface, doing a translation from subnet if necessary string localIF = Domain.DoSubnetTranslation(participant.getDomain().GetLocalInterface()); ISendDataHandler sender = null; if (t.GetTransport().Equals(Topic.TRANSPORT_MC)) { sender = new McSendDataHandler(t, localIF); } else if (t.GetTransport().Equals(Topic.TRANSPORT_TCP)) { sender = new TcpSendDataHandler(t, localIF); } if (sender != null) { SendDataHandlers.Add(key, sender); return(sender); } // We don't want to add the udp handler to the handler list, so handle this last if (t.GetTransport().Equals(Topic.TRANSPORT_UDP)) { if (udpSendDataHandler == null) { // We have only one sender for all topics, so use the domain value for buffer size udpSendDataHandler = new McUdpSendDataHandler( participant.getDomain().GetOutSocketBufferSize(), localIF); // Setup a listener on the participant info data published by participants on our domain. // We use the information for topics with UDP as transport, to know the destination for UDP sends // ie. we extract ip and port from the information and add it to our McUdpSendDataHandler partInfoListener = new ParticipantInfoDataListener(participant, udpSendDataHandler); partInfoSub = new Subscriber(participant.CreateParticipantInfoTopic()); partInfoSub.newDataDefault += new NewDataDefaultEventHandler(partInfoListener.SubscriberNewData); partInfoSub.Start(); } return(udpSendDataHandler); } throw new CommException("No such Transport " + t.GetTransport()); } catch (System.IO.IOException ex) { throw new CommException("Error creating SendDataHandler. IOException -->" + ex.Message); } }
///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) { // In the case that we use the same port for several topics, we need to find the sender for the transport::address::port used string key = t.GetTransport() + "::" + t.GetDomainAddress() + "::" + t.GetPort(); if (SendDataHandlers.ContainsKey(key)) { return SendDataHandlers[key]; } try { // Get the local interface, doing a translation from subnet if necessary string localIF = Domain.DoSubnetTranslation(participant.getDomain().GetLocalInterface()); ISendDataHandler sender = null; if (t.GetTransport().Equals(Topic.TRANSPORT_MC)) { sender = new McSendDataHandler(t, localIF); } else if (t.GetTransport().Equals(Topic.TRANSPORT_TCP)) { sender = new TcpSendDataHandler(t, localIF); } if (sender != null) { SendDataHandlers.Add(key, sender); return sender; } // We don't want to add the udp handler to the handler list, so handle this last if (t.GetTransport().Equals(Topic.TRANSPORT_UDP)) { if (udpSendDataHandler == null) { // We have only one sender for all topics, so use the domain value for buffer size udpSendDataHandler = new McUdpSendDataHandler( participant.getDomain().GetOutSocketBufferSize(), localIF); // Setup a listener on the participant info data published by participants on our domain. // We use the information for topics with UDP as transport, to know the destination for UDP sends // ie. we extract ip and port from the information and add it to our McUdpSendDataHandler partInfoListener = new ParticipantInfoDataListener(participant, udpSendDataHandler); partInfoSub = new Subscriber(participant.CreateParticipantInfoTopic()); partInfoSub.newDataDefault += new NewDataDefaultEventHandler(partInfoListener.SubscriberNewData); partInfoSub.Start(); } return udpSendDataHandler; } throw new CommException("No such Transport " + t.GetTransport()); } catch (System.IO.IOException ex) { throw new CommException("Error creating SendDataHandler. IOException -->" + ex.Message); } }
public TopicInfoData(Topic topic) { AppendType("TopicInfoData"); name = topic.GetName(); type = topic.GetTypeID(); transport = topic.GetTransport(); address = topic.GetDomainAddress(); port = topic.GetPort(); //keys; }
// Since topics can use the same port for transports multicast & tcp, or // use transport udp which always use a single ReceiveDataHandler, // we need to return the same ReceiveDataHandler in these cases. // Make a key with the transport info that uniquely defines the receiver. private string MakeKey(Topic top) { if (top.GetTransport().Equals(Topic.TRANSPORT_UDP)) { return(top.GetTransport()); } else { return(top.GetTransport() + "::" + top.GetDomainAddress() + "::" + top.GetPort()); } }
private void PostSetup(Topic t, Participant participant, McUdpSendDataHandler sdh) { // If topic specifies a valid node address, add that as a static destination address for topic if (Ops.InetAddress.IsValidNodeAddress(t.GetDomainAddress())) { sdh.AddSink(t.GetName(), t.GetDomainAddress(), t.GetPort(), true); } else { if (partInfoListener == null) { // Setup a listener on the participant info data published by participants on our domain. // We use the information for topics with UDP as transport, to know the destination for UDP sends // ie. we extract ip and port from the information and add it to our McUdpSendDataHandler partInfoListener = new ParticipantInfoDataListener(participant, sdh); partInfoSub = new Subscriber(participant.CreateParticipantInfoTopic()); partInfoSub.newDataDefault += new NewDataDefaultEventHandler(partInfoListener.SubscriberNewData); partInfoSub.Start(); } } }
public static IReceiver CreateReceiver(Topic topic, String localInterface) { try { if (topic.GetTransport().Equals(Topic.TRANSPORT_MC)) { return(new MulticastReceiver(topic.GetDomainAddress(), topic.GetPort(), localInterface, topic.GetInSocketBufferSize())); } else if (topic.GetTransport().Equals(Topic.TRANSPORT_TCP)) { return(new TcpClientReceiver(topic.GetDomainAddress(), topic.GetPort(), topic.GetInSocketBufferSize())); } else if (topic.GetTransport().Equals(Topic.TRANSPORT_UDP)) { return(new UdpReceiver(0, localInterface, topic.GetInSocketBufferSize())); } } catch (System.IO.IOException ex) { Logger.ExceptionLogger.LogMessage("CreateReceiver " + ex.ToString()); } return(null); }
public static IReceiver CreateReceiver(Topic topic, String localInterface) { try { if (topic.GetTransport().Equals(Topic.TRANSPORT_MC)) { return new MulticastReceiver(topic.GetDomainAddress(), topic.GetPort(), localInterface, topic.GetInSocketBufferSize()); } else if (topic.GetTransport().Equals(Topic.TRANSPORT_TCP)) { return new TcpClientReceiver(topic.GetDomainAddress(), topic.GetPort(), topic.GetInSocketBufferSize()); } else if (topic.GetTransport().Equals(Topic.TRANSPORT_UDP)) { return new UdpReceiver(0, localInterface, topic.GetInSocketBufferSize()); } } catch (System.IO.IOException ex) { Logger.ExceptionLogger.LogMessage("CreateReceiver " + ex.ToString()); } return null; }
private string MakeKey(Topic top, string localIf) { // In the case that we use the same port for several topics, we need to find the sender for the transport::address::port used string key = top.GetTransport() + "::"; if (top.GetTransport().Equals(Topic.TRANSPORT_UDP)) { key += localIf + "::"; } key += top.GetDomainAddress(); if (!top.GetTransport().Equals(Topic.TRANSPORT_UDP)) { key += "::" + top.GetPort(); } return(key); // t.GetTransport() + "::" + t.GetDomainAddress() + "::" + t.GetPort(); }
void checkTopicValues(Topic top) { if (top.GetDomainAddress().Equals("")) { top.SetDomainAddress(domainAddress); } if (top.GetLocalInterface().Equals("")) { top.SetLocalInterface(localInterface); } if (top.GetTimeToLive() < 0) { top.SetTimeToLive(timeToLive); } if (top.GetInSocketBufferSize() < 0) { top.SetInSocketBufferSize(inSocketBufferSize); } if (top.GetOutSocketBufferSize() < 0) { top.SetOutSocketBufferSize(outSocketBufferSize); } top.SetOptNonVirt(optNonVirt); }
// Since topics can use the same port for transports multicast & tcp, or // use transport udp which always use a single ReceiveDataHandler, // we need to return the same ReceiveDataHandler in these cases. // Make a key with the transport info that uniquely defines the receiver. private string MakeKey(Topic top) { if (top.GetTransport().Equals(Topic.TRANSPORT_UDP)) { return top.GetTransport(); } else { return top.GetTransport() + "::" + top.GetDomainAddress() + "::" + top.GetPort(); } }
public McSendDataHandler(Topic t, string localInterface) { sender = new MulticastSender(0, localInterface, 1, t.GetOutSocketBufferSize()); // Make ttl configurable sinkIP = InetAddress.GetByName(t.GetDomainAddress()); }
public TcpSendDataHandler(Topic t, string localInterface) { sender = new TcpServerSender(t.GetDomainAddress(), t.GetPort(), t.GetOutSocketBufferSize()); sinkIP = InetAddress.GetByName(t.GetDomainAddress()); }
public McSendDataHandler(Topic t, string localInterface, int ttl) { sender = new MulticastSender(0, localInterface, ttl, t.GetOutSocketBufferSize()); sinkIP = InetAddress.GetByName(t.GetDomainAddress()); }