Exemple #1
0
        static void Responder()
        {
            //
            // Initialize a second node for loopback testing
            //
            String g;

            ResponderThread.Name = "Responder thread for " + responderCallSign.ToUpper();
            Console.WriteLine(Thread.CurrentThread.Name + " starting");
            Byte[] tmpB  = new Byte[8192];
            Int32  count = 0;

            Connection.ConnectionStatus cstat;

            //
            // Create the DLP and connection
            //
            DataLinkProvider recvDlProvider = tncVHFChannel.CreateProvider(responderCallSign);
            Connection       tmpCon         = recvDlProvider.CreateConnection();

            tmpCon.registerStateHandlers.ReportConnectionEvents +=
                new EventHandler <ConnectionEvents>(NotifyConnectionState);
            tmpCon.registerIndicationHandlers.ReportIndicationEvents +=
                new EventHandler <IndicationEvents>(NotifyIndicationEvents);

            while (tmpCon.Enabled)
            {
                //
                // Wait for someone to connect to this instance.  Calling the
                // function with 'true' will cause the function to return only
                // if we enter the Connected state.  Normally the function will
                // return if either Connected or Disconnected
                //

                tmpCon.WaitForConnect(true);
                //
                // We're connected.  Perform any connection establishment work
                // here.  Lower loop handles data transfer while this current
                // connection is active
                //
                //
                // Loopback to the sender whatever we received
                //
                do
                {
                    //
                    // Loop here while connection is active
                    //
                    count = tmpCon.Recv(tmpB, true);
                    if (count > 0)
                    {
                        g = Encoding.ASCII.GetString(Support.PackByte(tmpB, 0, count));
                        if (g.StartsWith("bye"))
                        {
                            Console.WriteLine("Received a 'bye' command from the other station, so DISC");
                            cstat = tmpCon.Disconnect();
                            Console.WriteLine("Disconnect status: " + cstat.ToString());
                        }
                        else
                        {
                            //
                            // Loop back what was sent
                            //
                            Console.WriteLine(Thread.CurrentThread.Name + " Echoing: " + g);
                            tmpCon.Send(Encoding.ASCII.GetBytes(g));
                        }
                    }
                } while (tmpCon.isConnected);
            }
            Support.DbgPrint(Thread.CurrentThread.Name + " exiting");
        }