//
        // called when the type field changes
        //
        private void typeBox_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            browseList.Items.Clear();

            if (browser != null)
            {
                browser.Stop();
            }

            nameField.Text   = "";
            typeField.Text   = "";
            domainField.Text = "";
            hostField.Text   = "";
            portField.Text   = "";
            serviceTextField.Items.Clear();

            try
            {
                browser = service.Browse(0, 0, typeBox.SelectedItem.ToString(), null, eventManager);
            }
            catch
            {
                MessageBox.Show("Browse Failed", "Error");
                Application.Exit();
            }
        }
        ServiceResolved
        (
            DNSSDService sref,
            DNSSDFlags flags,
            uint ifIndex,
            String fullName,
            String hostName,
            ushort port,
            TXTRecord txtRecord
        )
        {
            m_resolver.Stop();
            m_resolver = null;

            PeerData peer = (PeerData)comboBox1.SelectedItem;

            peer.Port = port;

            try
            {
                m_resolver = m_service.QueryRecord(0, ifIndex, hostName, DNSSDRRType.kDNSSDType_A, DNSSDRRClass.kDNSSDClass_IN, m_eventManager);
            }
            catch
            {
                MessageBox.Show("QueryRecord Failed", "Error");
                Application.Exit();
            }
        }
Beispiel #3
0
        QueryAnswered
        (
            DNSSDService service,
            DNSSDFlags flags,
            uint ifIndex,
            String fullName,
            DNSSDRRType rrtype,
            DNSSDRRClass rrclass,
            Object rdata,
            uint ttl
        )
        {
            //
            // Stop the resolve to reduce the burden on the network
            //
            m_resolver.Stop();
            m_resolver = null;

            PeerData peer = (PeerData)comboBox1.SelectedItem;
            uint     bits = BitConverter.ToUInt32((Byte[])rdata, 0);

            System.Net.IPAddress address = new System.Net.IPAddress(bits);

            peer.Address = address;
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            IPEndPoint localEP = new IPEndPoint(System.Net.IPAddress.Any, 0);

            //
            // create the socket and bind to INADDR_ANY
            //
            m_socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            m_socket.Bind(localEP);
            localEP = (IPEndPoint)m_socket.LocalEndPoint;

            //
            // start asynchronous read
            //
            m_socket.BeginReceive(m_buffer, 0, BUFFER_SIZE, 0, new AsyncCallback(this.OnReadSocket), this);

            try
            {
                //
                // start the register and browse operations
                //
                m_registrar = m_service.Register(0, 0, System.Environment.UserName, "_p2pchat._udp", null, null, ( ushort )localEP.Port, null, m_eventManager);
            }
            catch
            {
                MessageBox.Show("Bonjour service is not available", "Error");
                Application.Exit();
            }
        }
        public SimpleChat()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            try
            {
                m_service = new DNSSDService();
            }
            catch
            {
                MessageBox.Show("Bonjour Service is not available", "Error");
                Application.Exit();
            }

            m_eventManager = new DNSSDEventManager();
            m_eventManager.ServiceRegistered   += new _IDNSSDEvents_ServiceRegisteredEventHandler(this.ServiceRegistered);
            m_eventManager.ServiceFound        += new _IDNSSDEvents_ServiceFoundEventHandler(this.ServiceFound);
            m_eventManager.ServiceLost         += new _IDNSSDEvents_ServiceLostEventHandler(this.ServiceLost);
            m_eventManager.ServiceResolved     += new _IDNSSDEvents_ServiceResolvedEventHandler(this.ServiceResolved);
            m_eventManager.QueryRecordAnswered += new _IDNSSDEvents_QueryRecordAnsweredEventHandler(this.QueryAnswered);
            m_eventManager.OperationFailed     += new _IDNSSDEvents_OperationFailedEventHandler(this.OperationFailed);

            m_readMessageCallback = new ReadMessageCallback(OnReadMessage);

            this.Load += new System.EventHandler(this.Form1_Load);

            this.AcceptButton = button1;
        }
        public void ServiceResolved
        (
            DNSSDService sref,
            DNSSDFlags flags,
            uint ifIndex,
            String fullName,
            String hostName,
            ushort port,
            TXTRecord txtRecord
        )
        {
            ResolveData data = new ResolveData();

            data.InterfaceIndex = ifIndex;
            data.FullName       = fullName;
            data.HostName       = hostName;
            data.Port           = port;
            data.TxtRecord      = txtRecord;

            //
            // Don't forget to stop the resolver. This eases the burden on the network
            //
            resolver.Stop();
            resolver = null;

            Populate((BrowseData)browseList.SelectedItem, data);
        }
        private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (resolver != null)
            {
                resolver.Stop();
                resolver = null;
            }

            if (browseList.SelectedItem != null)
            {
                try
                {
                    BrowseData data = (BrowseData)browseList.SelectedItem;

                    //
                    // Clicking on a service instance results in starting a resolve operation
                    // that will call us back with information about the service
                    //
                    resolver = service.Resolve(0, data.InterfaceIndex, data.Name, data.Type, data.Domain, eventManager);
                }
                catch
                {
                    MessageBox.Show("Resolve Failed", "Error");
                    Application.Exit();
                }
            }
        }
        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            this.Load += new System.EventHandler(this.Form1_Load);

            //
            // Create the DNSSDEventManager. You can then associate event handlers
            // with the instance that will be invoked when the event occurs
            //
            // In this example, we're associating ServiceFound, ServiceLost,
            // ServiceResolved, and OperationFailed event handlers with the
            // event manager instance.
            //
            eventManager = new DNSSDEventManager();
            eventManager.ServiceFound    += new _IDNSSDEvents_ServiceFoundEventHandler(this.ServiceFound);
            eventManager.ServiceLost     += new _IDNSSDEvents_ServiceLostEventHandler(this.ServiceLost);
            eventManager.ServiceResolved += new _IDNSSDEvents_ServiceResolvedEventHandler(this.ServiceResolved);
            eventManager.OperationFailed += new _IDNSSDEvents_OperationFailedEventHandler(this.OperationFailed);

            service = new DNSSDService();
        }
Beispiel #9
0
        ServiceRegistered

        (

            DNSSDService service,

            DNSSDFlags flags,

            String name,

            String regType,

            String domain

        )

        {
            m_name = name;



            try

            {
                m_browser = m_service.Browse(0, 0, "_p2pchat._udp", null, m_eventManager);
            }

            catch

            {
                MessageBox.Show("Browse Failed", "Error");

                Application.Exit();
            }
        }
Beispiel #10
0
        public Server()
        {
            InitializeComponent();

            try
            {
                m_service = new DNSSDService();
                m_eventManager = new DNSSDEventManager();
            }
            catch
            {
                MessageBox.Show("Bonjour Service is not available", "Error");
                Application.Exit();
            }

            CheckForIllegalCrossThreadCalls = false;
            StartGetNodeNumber();

            // create the async listening sockets
            for (int i = 0; i < MAXCONNECTIONS; i++)
                connections[i] = new Connection();
            IPEndPoint ep = new IPEndPoint(IPAddress.Any, 0);
            listenSocket.Bind(ep);
            listenSocket.Listen(100);
            listenSocket.BeginAccept(new AsyncCallback(Acceptcallback), 0);
            ep = ((IPEndPoint)listenSocket.LocalEndPoint);
            m_registrar = m_service.Register(0, 0, System.Environment.UserName, "_withrottle._tcp", null, null, (ushort)ep.Port, null, null);
            log("WiThrottle Port " + ep.Port.ToString());
        }
        //
        // called when peer target changes
        //
        /// <summary>
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            PeerData peer = (PeerData)comboBox1.SelectedItem;

            try
            {
                m_resolver = m_service.Resolve(0, peer.InterfaceIndex, peer.Name, peer.Type, peer.Domain, m_eventManager);
            }
            catch
            {
                MessageBox.Show("Unable to Resolve service", "Error");
                Application.Exit();
            }
        }
Beispiel #12
0
 public Throttle()
 {
     InitializeComponent();
     try
     {
         m_service = new DNSSDService();
         m_eventManager = new DNSSDEventManager();
     }
     catch
     {
         MessageBox.Show("Bonjour Service is not available", "Error");
         Application.Exit();
     }
     StartGetNodeNumber();
 }
        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            this.Load += new System.EventHandler(this.Form1_Load);

            eventManager = new DNSSDEventManager();
            eventManager.ServiceFound    += new _IDNSSDEvents_ServiceFoundEventHandler(this.ServiceFound);
            eventManager.ServiceLost     += new _IDNSSDEvents_ServiceLostEventHandler(this.ServiceLost);
            eventManager.ServiceResolved += new _IDNSSDEvents_ServiceResolvedEventHandler(this.ServiceResolved);
            eventManager.OperationFailed += new _IDNSSDEvents_OperationFailedEventHandler(this.OperationFailed);

            service = new DNSSDService();
        }
        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            this.Load += new System.EventHandler(this.Form1_Load);

            eventManager                    =  new DNSSDEventManager();
            eventManager.ServiceFound       += new _IDNSSDEvents_ServiceFoundEventHandler(this.ServiceFound);
            eventManager.ServiceLost        += new _IDNSSDEvents_ServiceLostEventHandler(this.ServiceLost);
            eventManager.ServiceResolved    += new _IDNSSDEvents_ServiceResolvedEventHandler(this.ServiceResolved);
            eventManager.OperationFailed    += new _IDNSSDEvents_OperationFailedEventHandler(this.OperationFailed);

            service = new DNSSDService();
        }
Beispiel #15
0
 public Form1()
 {
     InitializeComponent();
     CheckForIllegalCrossThreadCalls = false;
     try
     {
         m_service = new DNSSDService();
         m_eventManager = new DNSSDEventManager();
     }
     catch
     {
         MessageBox.Show("Bonjour Service is not available", "Error");
         Application.Exit();
     }
     StartGetNodeNumber();
     clocktask = new Thread(clockticktask);
     clocktask.Start();
 }
        public void PublishBonjour()
        {
            Logger.Instance.eventLog.WriteEntry("Starting Bonjour", EventLogEntryType.Information);
            try
            {
                bonjourService = new DNSSDService();
            }
            catch
            {
                return;
            }
            String type = "_istatserv._tcp";
            String name = String.Format("{0},{1}", Clients.Instance.ServerUUID(), Environment.MachineName);

            Bonjour.TXTRecord record = new TXTRecord();
            record.SetValue("model", "windows");
            record.SetValue("time", String.Format("{0}", DateTime.Now.Ticks));
            //manager.ServiceRegistered += new _IDNSSDEvents_ServiceRegisteredEventHandler(this.ServiceRegistered);
            Logger.Instance.eventLog.WriteEntry("Registering Bonjour Service", EventLogEntryType.Information);
            bonjourServiceRegistrar = bonjourService.Register(0, 0, name, type, null, null, ushort.Parse(Preferences.Instance.Value("port")), record, null);
        }
        public void PublishBonjour()
        {
            Logger.Instance.eventLog.WriteEntry("Starting Bonjour", EventLogEntryType.Information);
            try
            {
                bonjourService = new DNSSDService();
            }
            catch
            {
                return;
            }
            String type = "_istatserv._tcp";
            String name = String.Format("{0},{1}", Clients.Instance.ServerUUID(), Environment.MachineName);

            Bonjour.TXTRecord record = new TXTRecord();
            record.SetValue("model", "windows");
            record.SetValue("time", String.Format("{0}", DateTime.Now.Ticks));
            //manager.ServiceRegistered += new _IDNSSDEvents_ServiceRegisteredEventHandler(this.ServiceRegistered);
            Logger.Instance.eventLog.WriteEntry("Registering Bonjour Service", EventLogEntryType.Information);
            bonjourServiceRegistrar = bonjourService.Register(0, 0, name, type, null, null, ushort.Parse(Preferences.Instance.Value("port")), record, null);
        }
Beispiel #18
0
        // QueryAnswered
        //
        // Called by DNSServices core as a result of DNSService.QueryRecord()
        public void QueryAnswered(DNSSDService service, DNSSDFlags flags, uint ifIndex, String fullName, DNSSDRRType rrtype, DNSSDRRClass rrclass, Object rdata, uint ttl)
        {
            m_resolver.Stop();
            m_resolver = null;

            PeerData peer = this.selectedPeer;

            uint bits = BitConverter.ToUInt32((Byte[])rdata, 0);
            System.Net.IPAddress address = new System.Net.IPAddress(bits);

            peer.Address = address;

            try
            {
                IPEndPoint ipe = new IPEndPoint(address, peer.Port);
                m_socket.Connect(ipe);
                m_socket.BeginReceive(m_buffer, 0, BUFFER_SIZE, 0, new AsyncCallback(this.OnReadSocket), this);
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.Message);
            }
        }
        private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (resolver != null)
            {
                resolver.Stop();
                resolver = null;
            }

            if (browseList.SelectedItem != null)
            {
                try
                {
                    BrowseData data = (BrowseData)browseList.SelectedItem;

                    resolver = service.Resolve(0, data.InterfaceIndex, data.Name, data.Type, data.Domain, eventManager);
                }
                catch
                {
                    MessageBox.Show("Resolve Failed", "Error");
                    Application.Exit();
                }
            }
        }
Beispiel #20
0
        //
        // ServiceResolved
        //
        // Called by DNSServices core as a result of DNSService.Resolve()
        // call
        //
        public void ServiceResolved(

                    DNSSDService sref,

                    DNSSDFlags flags,

                    uint ifIndex,

                    String fullName,

                    String hostName,

                    ushort port,

                    TXTRecord txtRecord

                    )
        {
            m_resolver.Stop();

            m_resolver = null;

            PeerData peer = (PeerData)comboBox1.SelectedItem;

            peer.Port = port;

            try

            {

                m_resolver = m_service.QueryRecord(0, ifIndex, hostName, DNSSDRRType.kDNSSDType_A, DNSSDRRClass.kDNSSDClass_IN, m_eventManager );

            }

            catch

            {

                MessageBox.Show("QueryRecord Failed", "Error");

                Application.Exit();

            }
        }
Beispiel #21
0
        // ServiceRegistered
        //
        // Called by DNSServices core as a result of Register()
        // call
        //
        public void ServiceRegistered(

                    DNSSDService service,

                    DNSSDFlags flags,

                    String name,

                    String regType,

                    String domain

                    )
        {
            m_name = name;

            try

            {

                m_browser = m_service.Browse(0, 0, "_p2pchat._udp", null, m_eventManager);

            }

            catch

            {

                MessageBox.Show("Browse Failed", "Error");

                Application.Exit();

            }
        }
Beispiel #22
0
        //
        // QueryAnswered
        //
        // Called by DNSServices core as a result of DNSService.QueryRecord()
        // call
        //
        public void QueryAnswered(
            DNSSDService    service, 
            DNSSDFlags      flags,
            uint            ifIndex,
            String          fullName,
            DNSSDRRType     rrtype,
            DNSSDRRClass    rrclass,
            Object          rdata,
            uint            ttl
            )
        {
            m_resolver.Stop();

            m_resolver = null;

            PeerData peer = (PeerData) comboBox1.SelectedItem;

            uint bits = BitConverter.ToUInt32( (Byte[])rdata, 0);
            System.Net.IPAddress address = new System.Net.IPAddress(bits);

            peer.Address = address;
        }
Beispiel #23
0
        public SimpleChat()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            try

            {

                m_service = new DNSSDService();

            }

            catch

            {

                MessageBox.Show("Bonjour Service is not available", "Error");

                Application.Exit();

            }

            m_eventManager = new DNSSDEventManager();

            m_eventManager.ServiceRegistered += new _IDNSSDEvents_ServiceRegisteredEventHandler(this.ServiceRegistered);

            m_eventManager.ServiceFound += new _IDNSSDEvents_ServiceFoundEventHandler(this.ServiceFound);

            m_eventManager.ServiceLost += new _IDNSSDEvents_ServiceLostEventHandler(this.ServiceLost);

            m_eventManager.ServiceResolved += new _IDNSSDEvents_ServiceResolvedEventHandler(this.ServiceResolved);

            m_eventManager.QueryRecordAnswered += new _IDNSSDEvents_QueryRecordAnsweredEventHandler(this.QueryAnswered);

            m_eventManager.OperationFailed += new _IDNSSDEvents_OperationFailedEventHandler(this.OperationFailed);

            m_readMessageCallback = new ReadMessageCallback(OnReadMessage);

            this.Load += new System.EventHandler(this.Form1_Load);

            this.AcceptButton = button1;
        }
        public void ServiceResolved(
						DNSSDService    sref,  
						DNSSDFlags      flags,
						uint			ifIndex,
                        String          fullName,
                        String          hostName,
                        ushort           port,
                        TXTRecord       txtRecord
						)
        {
            ResolveData data = new ResolveData();

            data.InterfaceIndex = ifIndex;
            data.FullName		= fullName;
            data.HostName		= hostName;
            data.Port			= port;
            data.TxtRecord		= txtRecord;

            //
            // Don't forget to stop the resolver. This eases the burden on the network
            //
            resolver.Stop();
            resolver = null;

            Populate((BrowseData) browseList.SelectedItem, data);
        }
Beispiel #25
0
        // ServiceRegistered
        //
        // Called by DNSServices core as a result of Register()
        public void ServiceRegistered(DNSSDService service, DNSSDFlags flags, String name, String regType, String domain)
        {
            m_name = name;

            try
            {
                m_browser = m_service.Browse(0, 0, regName, null, m_eventManager);
                System.Console.WriteLine("Registered as " + m_name + "...");
                System.Console.WriteLine("Waiting for a connection...");
            }
            catch
            {
                System.Console.WriteLine("Error - Browse Failed");
            }
        }
Beispiel #26
0
        public ComGateway()
        {
            InitializeComponent();
            CheckForIllegalCrossThreadCalls = false;

            String[] arguments = Environment.GetCommandLineArgs();
            for (int a = 1; a < arguments.Length; a++)
            {
                localhub = true;
                log("Arg " + arguments[a]);
                if (arguments[a].StartsWith("port"))
                {
                    int p = arguments[a].IndexOf('=');
                    if (p > 0)
                        port = Convert.ToInt32(arguments[a].Substring(p + 1));
                }
            }

            if (localhub)
            {
                IPEndPoint ep = new IPEndPoint(IPAddress.Loopback, port);
                skt.Connect(ep);
                byte[] buffer = new byte[12];
                skt.Receive(buffer);
                if ((buffer[1] << 8) + buffer[2] == NODENUMBER)
                {
                    nodenumber = ((long)buffer[3] << 40) + ((long)buffer[4] << 32) + (buffer[5] << 24)
                        + (buffer[6] << 16) + (buffer[7] << 8) + buffer[8];
                    nodenumberstr = nodenumber.ToString("X12");
                    log("OpenLCB Node Number " + nodenumberstr);
                }
                else
                {
                    log("No node number allocated.");
                    return;
                }
                serverconnected = true;
                skt.BeginReceive(inputbuffer, 0, 2000, SocketFlags.None, (AsyncCallback)InputTask, skt);
                EthernetSendHexString(INITCOMPLETE + nodenumberstr + nodenumberstr);
            }
            else
            {
                try
                {
                    m_service = new DNSSDService();
                    m_eventManager = new DNSSDEventManager();
                }
                catch
                {
                    MessageBox.Show("Bonjour Service is not available", "Error");
                    Application.Exit();
                }

                StartGetNodeNumber();
            }
        }
Beispiel #27
0
        // called when peer target changes
        private void selectNewPeer()
        {
            PeerData peer = this.selectedPeer;

            try
            {
                m_resolver = m_service.Resolve(0, peer.InterfaceIndex, peer.Name, peer.Type, peer.Domain, m_eventManager);
            }
            catch
            {
                System.Console.WriteLine("Error - Unable to Resolve service");
            }
        }
        private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (resolver != null)
            {
                resolver.Stop();
                resolver = null;
            }

            if (browseList.SelectedItem != null)
            {
                try
                {
                    BrowseData data = (BrowseData) browseList.SelectedItem;

                    resolver = service.Resolve(0, data.InterfaceIndex, data.Name, data.Type, data.Domain, eventManager);
                }
                catch
                {
                    MessageBox.Show("Resolve Failed", "Error");
                    Application.Exit();
                }
            }
        }
Beispiel #29
0
        //***************************************************************************
        // Connect to OpenLCB
        //***************************************************************************
        public void StartOpenLCBConnect()
        {
            // Start
            m_eventManager.ServiceFound += new _IDNSSDEvents_ServiceFoundEventHandler(ServiceFound);

            // Browse
            try
            {
                // params service discovery ref, interface index = 0 for all, service name,
                //      domain, callback fn, context=null
                m_browser = m_service.Browse(0, 0, "_OpenLCB._tcp", null, m_eventManager);
            }
            catch
            {
                log("OpenLCB Server browse Failed");
                Thread.Sleep(1000);
                m_eventManager.ServiceFound -= new _IDNSSDEvents_ServiceFoundEventHandler(ServiceFound);
                Application.Exit();
            }
        }
Beispiel #30
0
        //
        // called when peer target changes
        //
        /// <summary>
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            PeerData peer = (PeerData) comboBox1.SelectedItem;

            try
            {
                m_resolver = m_service.Resolve(0, peer.InterfaceIndex, peer.Name, peer.Type, peer.Domain, m_eventManager);
            }
            catch
            {
                MessageBox.Show("Unable to Resolve service", "Error");
                Application.Exit();
            }
        }
Beispiel #31
0
        private void load()
        {
            IPEndPoint localEP = new IPEndPoint(System.Net.IPAddress.Any, 0);

            // create the socket and bind to INADDR_ANY
            m_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            m_socket.Bind(localEP);
            localEP = (IPEndPoint)m_socket.LocalEndPoint;

            // start asynchronous read
            // m_socket.BeginReceive(m_buffer, 0, BUFFER_SIZE, 0, new AsyncCallback(this.OnReadSocket), this);

            try
            {
                // start the register and browse operations
                m_registrar = m_service.Register(0, 0, System.Environment.UserName, regName, null, null, (ushort)localEP.Port, null, m_eventManager);
                //m_socket.Listen(32);
                //m_socket = m_socket.Accept();
                //m_socket.BeginReceive(m_buffer, 0, BUFFER_SIZE, 0, new AsyncCallback(this.OnReadSocket), this);
            }
            catch
            {
                System.Console.WriteLine("Error - Bonjour service is not available");
            }
        }
Beispiel #32
0
        private void Form1_Load(object sender, EventArgs e)
        {
            IPEndPoint localEP = new IPEndPoint(System.Net.IPAddress.Any, 0);

            //
            // create the socket and bind to INADDR_ANY
            //
            m_socket	= new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            m_socket.Bind(localEP);
            localEP = (IPEndPoint) m_socket.LocalEndPoint;

            //
            // start asynchronous read
            //
            m_socket.BeginReceive(m_buffer, 0, BUFFER_SIZE, 0, new AsyncCallback(this.OnReadSocket), this);

            try
            {
                //
                // start the register and browse operations
                //
                m_registrar	=	m_service.Register( 0, 0, System.Environment.UserName, "_p2pchat._udp", null, null, ( ushort ) localEP.Port, null, m_eventManager );
            }
            catch
            {
                MessageBox.Show("Bonjour service is not available", "Error");
                Application.Exit();
            }
        }
Beispiel #33
0
        private void initialize()
        {
            try
            {
                m_service = new DNSSDService();
            }
            catch
            {
                System.Console.WriteLine("Error - Bonjour Service is not available");
            }

            m_eventManager = new DNSSDEventManager();
            m_eventManager.ServiceRegistered += new _IDNSSDEvents_ServiceRegisteredEventHandler(this.ServiceRegistered);
            m_eventManager.ServiceFound += new _IDNSSDEvents_ServiceFoundEventHandler(this.ServiceFound);
            m_eventManager.ServiceLost += new _IDNSSDEvents_ServiceLostEventHandler(this.ServiceLost);
            m_eventManager.ServiceResolved += new _IDNSSDEvents_ServiceResolvedEventHandler(this.ServiceResolved);
            m_eventManager.QueryRecordAnswered += new _IDNSSDEvents_QueryRecordAnsweredEventHandler(this.QueryAnswered);
            m_eventManager.OperationFailed += new _IDNSSDEvents_OperationFailedEventHandler(this.OperationFailed);

            this.rayTracer = new RayTracer();

            this.load();
        }
Beispiel #34
0
        public void StartGetNodeNumber()
        {
            // Start
            m_eventManager.ServiceFound += new _IDNSSDEvents_ServiceFoundEventHandler(ServiceFound);

            // Browse
            try
            {
                // params service discovery ref, interface index = 0 for all, service name,
                //      domain, callback fn, context=null
                m_browser = m_service.Browse(0, 0, "_OpenLCB._tcp", null, m_eventManager);
            }
            catch
            {
                MessageBox.Show("OpenLCB server browse Failed", "Error");
                m_eventManager.ServiceFound -= new _IDNSSDEvents_ServiceFoundEventHandler(ServiceFound);
                Application.Exit();
            }
        }
Beispiel #35
0
        // ServiceResolved
        //
        // Called by DNSServices core as a result of DNSService.Resolve()
        public void ServiceResolved(DNSSDService sref, DNSSDFlags flags, uint ifIndex, String fullName, String hostName, ushort port, TXTRecord txtRecord)
        {
            m_resolver.Stop();
            m_resolver = null;

            PeerData peer = this.selectedPeer;

            peer.Port = port;

            try
            {
                m_resolver = m_service.QueryRecord(0, ifIndex, hostName, DNSSDRRType.kDNSSDType_A, DNSSDRRClass.kDNSSDClass_IN, m_eventManager);
            }
            catch
            {
                System.Console.WriteLine("Error - QueryRecord Failed");
            }
        }
        private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (resolver != null)
            {
                resolver.Stop();
                resolver = null;
            }

            if (browseList.SelectedItem != null)
            {
                try
                {
                    BrowseData data = (BrowseData) browseList.SelectedItem;

                    //
                    // Clicking on a service instance results in starting a resolve operation
                    // that will call us back with information about the service
                    //
                    resolver = service.Resolve(0, data.InterfaceIndex, data.Name, data.Type, data.Domain, eventManager);
                }
                catch
                {
                    MessageBox.Show("Resolve Failed", "Error");
                    Application.Exit();
                }
            }
        }
Beispiel #37
0
        public Config()
        {
            InitializeComponent();
            try
            {
                m_service = new DNSSDService();
                m_eventManager = new DNSSDEventManager();
            }
            catch
            {
                MessageBox.Show("Bonjour Service is not available", "Error");
                Application.Exit();
            }

            CheckForIllegalCrossThreadCalls = false;

            for (int i = 0; i < 4; i++)
            {
                idlabels[i] = new Label();
                idlabels[i].AutoSize = true;
                idlabels[i].Size = new System.Drawing.Size(50, 13);
                idlabels[i].Location = new System.Drawing.Point(10, i * 25 + 50);
                idlabels[i].Visible = false;
                Controls.Add(idlabels[i]);
                idtextboxes[i] = new TextBox();
                idtextboxes[i].Location = new System.Drawing.Point(90, i * 25 + 50);
                idtextboxes[i].Size = new System.Drawing.Size(280, 20);
                idtextboxes[i].ReadOnly = true;
                idtextboxes[i].Visible = false;
                Controls.Add(idtextboxes[i]);
            }
            for (int i = 0; i < 10; i++)
            {
                labels[i] = new Label();
                labels[i].AutoSize = true;
                labels[i].Visible = false;
                groupBox1.Controls.Add(labels[i]);
                textboxes[i] = new TextBox();
                textboxes[i].Size = new System.Drawing.Size(160, 20);
                textboxes[i].Validating += new CancelEventHandler(this.textBox_Validating);
                textboxes[i].Visible = false;
                groupBox1.Controls.Add(textboxes[i]);
                numbers[i] = new NumericUpDown();
                numbers[i].Visible = false;
                numbers[i].ValueChanged += new EventHandler(this.numericUpDown_ValueChanged);
                groupBox1.Controls.Add(numbers[i]);
            }
            setBtns(0);

            StartGetNodeNumber();
            GetNodeNames = new Thread(GetNodeName);
            GetNodeNames.Start();
        }
Beispiel #38
0
        // callback from browse
        // params service discovery ref, status flags, interface index, error code ?, service name,
        //      registration type, domain, context=null
        public void ServiceFound(DNSSDService sref, DNSSDFlags flags, uint ifIndex, String serviceName,
            String regType, String domain)
        {
            m_browser.Stop();
            m_eventManager.ServiceFound -= new _IDNSSDEvents_ServiceFoundEventHandler(ServiceFound);
            m_eventManager.ServiceResolved += new _IDNSSDEvents_ServiceResolvedEventHandler(ServiceResolved);

            try
            {
                m_resolver = m_service.Resolve(0, ifIndex, serviceName, regType, domain, m_eventManager);
            }
            catch
            {
                log("Unable to Resolve service");
                Thread.Sleep(1000);
                // tidy up
                m_eventManager.ServiceResolved -= new _IDNSSDEvents_ServiceResolvedEventHandler(ServiceResolved);
                Application.Exit();
            }
        }
        //
        // called when the type field changes
        //
        private void typeBox_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            browseList.Items.Clear();

            //
            // Stop the current browse operation
            //
            if (browser != null)
            {
                browser.Stop();
            }

            nameField.Text = "";
            typeField.Text = "";
            domainField.Text = "";
            hostField.Text = "";
            portField.Text = "";
            serviceTextField.Items.Clear();

            try
            {
                //
                // Selecting a service type will start a new browse operation.
                //
                browser = service.Browse( 0, 0, typeBox.SelectedItem.ToString(), null, eventManager );
            }
            catch
            {
                MessageBox.Show("Browse Failed", "Error");
                Application.Exit();
            }
        }
Beispiel #40
0
        public OlcbSvr()
        {
            InitializeComponent();
            CheckForIllegalCrossThreadCalls = false;
            try
            {
                m_service = new DNSSDService();
                m_eventManager = new DNSSDEventManager();
                m_eventManager.OperationFailed += new _IDNSSDEvents_OperationFailedEventHandler(OperationFailed);
             }
            catch
            {
                log("Bonjour Service is not available");
            }

            String[] arguments = Environment.GetCommandLineArgs();
            for (int a = 1; a < arguments.Length; a++)
            {
                localhub = true;
                log("Arg " + arguments[a]);
                if (arguments[a].StartsWith("port"))
                {
                    int p = arguments[a].IndexOf('=');
                    if (p > 0)
                        port = Convert.ToInt32(arguments[a].Substring(p+1));
                }
                if (arguments[a].StartsWith("max"))
                {
                    int p = arguments[a].IndexOf('=');
                    if (p > 0)
                        MAXCONNECTIONS = Convert.ToInt32(arguments[a].Substring(p+1));
                }
            }

            if (!localhub)
            {
                // create the async listening sockets
                ep = new IPEndPoint(IPAddress.Any, 0);
                ServerSkt.Bind(ep);
                ServerSkt.Listen(1);
                ServerSkt.BeginAccept(new AsyncCallback(Acceptcallback), 0);
                ep = ((IPEndPoint)ServerSkt.LocalEndPoint);
                log("OpenLCB Hub start on port " + ep.Port.ToString());
                // register server with zeroconfig, (alias bonjour)
                // params (flags, interface, instancename, servicetype, domain, host, port, TXTrecord, eventmanager)
                m_registrar = m_service.Register(DNSSDFlags.kDNSSDFlagsNoAutoRename, 0, "OpenLCB Hub Service",
                    "_OpenLCB._tcp", null, null, (ushort)ep.Port, null, m_eventManager);
            }
            if (localhub)
            {
                // connect via bonjour
                StartOpenLCBConnect();

                // create the async listening sockets
                ep = new IPEndPoint(IPAddress.Loopback, port);
                ServerSkt.Bind(ep);
                ServerSkt.Listen(1);
                ServerSkt.BeginAccept(new AsyncCallback(Acceptcallback), 0);
                ep = ((IPEndPoint)ServerSkt.LocalEndPoint);
                log("OpenLCB Hub start on port " + ep.Port.ToString());
            }

            if (!localhub)
                readxmldata();

            MaxConTB.Text = MAXCONNECTIONS.ToString();
            connects = new CONNECTION[MAXCONNECTIONS];
            for (int i = 0; i < MAXCONNECTIONS; i++)
                connects[i] = new CONNECTION();

            // node number server range
            GroupBox.Items.Add("NMRA");
            GroupBox.Items.Add("MERG");
            GroupBox.Items.Add("Fremo");
            GroupBox.Items.Add("Ntrak");
            RangeFromTB.Text = servernodenumber.ToString("X12");
            SetGroup(RangeFromTB.Text);
            byte6txt.Text = Convert.ToInt32(RangeFromTB.Text.Substring(10, 2), 16).ToString();
            membertxt.Text = Convert.ToInt32(RangeFromTB.Text.Substring(4, 6), 16).ToString();

            inithub();
        }
        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            this.Load += new System.EventHandler(this.Form1_Load);

            //
            // Create the DNSSDEventManager. You can then associate event handlers
            // with the instance that will be invoked when the event occurs
            //
            // In this example, we're associating ServiceFound, ServiceLost,
            // ServiceResolved, and OperationFailed event handlers with the
            // event manager instance.
            //
            eventManager                    =  new DNSSDEventManager();
            eventManager.ServiceFound       += new _IDNSSDEvents_ServiceFoundEventHandler(this.ServiceFound);
            eventManager.ServiceLost        += new _IDNSSDEvents_ServiceLostEventHandler(this.ServiceLost);
            eventManager.ServiceResolved    += new _IDNSSDEvents_ServiceResolvedEventHandler(this.ServiceResolved);
            eventManager.OperationFailed    += new _IDNSSDEvents_OperationFailedEventHandler(this.OperationFailed);

            service = new DNSSDService();
        }