コード例 #1
0
        public void run(int port)
        {
            TcpListener listen = new TcpListener(port);

            listen.Start();

            Console.WriteLine("server awaiting connections...");

            while (true)
            {
                TcpClient client  = listen.AcceptTcpClient();
                Tagging   tagging = MultiAppDotNet.getTagging();
                Console.WriteLine("accepted client");

                BigEndianReaderWriter rw = new BigEndianReaderWriter(client.GetStream());

                // read the dynaTrace tag (if present) and set it
                byte length = rw.ReadByte();
                // if length != 0, the message contains a dynaTrace tag
                if (length != 0)
                {
                    byte[] tag = rw.ReadBytes(length);
                    tagging.setTag(tag);
                }

                // reading "payload"
                long a = rw.ReadInt64();
                long b = rw.ReadInt64();

                // no dynaTrace tag was sent => we assume that the data itself were used as "custom tag"
                if (length == 0)
                {
                    byte[] customTag = MultiAppDotNet.getCustomTagFromData(a, b);
                    tagging.setCustomTag(customTag);
                }

                // start server-side PurePath
                tagging.startServerPurePath();

                long r = multiply(a, b);
                Console.WriteLine(a + "*" + b + "=" + r);
                rw.WriteInt64(r);

                // end server-side PurePath
                MultiAppDotNet.getTagging().endServerPurePath();

                client.Close();
            }
        }
コード例 #2
0
ファイル: Client.cs プロジェクト: dmauney/Dynatrace
        public void run(string host, int port, bool use_dt_tag)
        {
            TcpClient client  = new TcpClient(host, port);
            Tagging   tagging = MultiAppDotNet.getTagging();

            long a = random.Next();
            long b = random.Next();

            BigEndianReaderWriter rw = new BigEndianReaderWriter(client.GetStream());

            // Either use dynaTrace tags or "custom tags" (passive tagging) for linking remote calls
            if (use_dt_tag)
            {
                // get the current dynaTrace tag and transmit it to the server
                byte[] tag = tagging.getTag();
                rw.WriteByte((byte)tag.Length);
                rw.WriteBytes(tag);
                // insert a synchronous link node
                tagging.linkClientPurePath(false);
            }
            else
            {
                // when using "custom tagging" we're using the data itself as "custom tag"
                CustomTag customTag = tagging.createCustomTag(MultiAppDotNet.getCustomTagFromData(a, b));
                // write a 0 byte, indicating that *no* tag is being sent
                rw.WriteByte((byte)0);
                // insert a synchronous link node using our specific customTag
                tagging.linkClientPurePath(false, customTag);
            }

            // send "payload"
            rw.WriteInt64(a);
            rw.WriteInt64(b);

            // read response from server
            long r = rw.ReadInt64();

            Console.WriteLine(a + "*" + b + "=" + r);

            client.Close();
        }