private byte[] MessageToPacketBytes(Message message)
        {
            Transmitter transmitter = new Transmitter();

            transmitter.DefaultPacketFirstSentTime = new DateTime(2009, 11, 5, 15, 33, 25);
            Session session = transmitter.OpenSession("127.0.0.1", UdpClientPort, null);

            session.Send(message);
            transmitter.Send();

            Thread.Sleep(100);

            byte[]       receivedBytes;
            IPEndPoint   remoteEndPoint = null;
            MemoryStream stream         = new MemoryStream(10);

            while (udpClient.Available > 0)
            {
                receivedBytes = udpClient.Receive(ref remoteEndPoint);
                stream.Write(receivedBytes, 0, receivedBytes.Length);
            }
            byte[] sourceBytes = stream.GetBuffer();
            byte[] targetBytes = new byte[stream.Length];

            for (int i = 0; i < targetBytes.Length; i++)
            {
                targetBytes[i] = sourceBytes[i];
            }

            return(targetBytes);
        }
Example #2
0
        /// <summary>
        /// Connects to a bubble with given address and identity information.
        /// </summary>
        /// <param name="hostname">Bubble server address</param>
        /// <param name="port">Bubble server port</param>
        /// <param name="bubbleId">Unique identifier of the bubble</param>
        /// <param name="bubbleName">Should be set to "" if bubbleId is not empty guid.</param>
        /// <param name="location">Name of the virtual location where participant is placed on connect</param>
        /// <param name="identityProviderUrl">Url of the identity provider. For example OpenId provider.</param>
        /// <param name="participantIdentifier">Participant name</param>
        /// <param name="participantSecret">Participant passphrase</param>
        public void Connect(String hostname, int port, Guid bubbleId, string bubbleName, string location, String identityProviderUrl, string participantIdentifier, string participantSecret, Guid avatarId, bool debugMessages)
        {
            Startup();

            JoinRequestMessage message = (JoinRequestMessage)MessageFactory.Current.ReserveMessage(typeof(JoinRequestMessage));

            session = transmitter.OpenSession(hostname, port, message);
            session.DebugMessages = debugMessages;

            message.BubbleId              = bubbleId;
            message.BubbleName            = bubbleName;
            message.LocationName          = location;
            message.IdentityProviderUrl   = identityProviderUrl;
            message.ParticipantIdentifier = participantIdentifier;
            message.ParticipantSecret     = participantSecret;
            message.ParticipantRealTime   = 0;
            message.AvatarId              = avatarId;

            message.ProgramName            = programName;
            message.ProgramMajorVersion    = programMajorVersion;
            message.ProgramMinorVersion    = programMinorVersion;
            message.ProtocolMajorVersion   = MxpConstants.ProtocolMajorVersion;
            message.ProtocolMinorVersion   = MxpConstants.ProtocolMinorVersion;
            message.ProtocolSourceRevision = MxpConstants.ProtocolSourceRevision;

            session.Send(message);
        }
Example #3
0
        public void TransmitterConnectivity()
        {
            Transmitter server = new Transmitter(MxpConstants.DefaultHubPort);

            Transmitter client = new Transmitter();

            JoinRequestMessage originalMessage = new JoinRequestMessage();

            originalMessage.BubbleId              = Guid.NewGuid();
            originalMessage.LocationName          = "TestLocation";
            originalMessage.IdentityProviderUrl   = "IdentityProviderUrl";
            originalMessage.ParticipantIdentifier = "TestParticipantName";
            originalMessage.ParticipantSecret     = "TestParticipantPassphrase";
            originalMessage.ParticipantRealTime   = 10;

            originalMessage.ProgramName          = "TestProgramName";
            originalMessage.ProgramMajorVersion  = 1;
            originalMessage.ProgramMinorVersion  = 2;
            originalMessage.ProtocolMajorVersion = 3;
            originalMessage.ProtocolMinorVersion = 4;

            Session clientSession = client.OpenSession("127.0.0.1", MxpConstants.DefaultHubPort, originalMessage);

            clientSession.Send(originalMessage);
            client.Send();

            Assert.AreEqual(1, clientSession.GetPacketWaitingAcknowledgeCount());

            Thread.Sleep(100);

            server.Receive();

            server.Send();

            Thread.Sleep(100);

            client.Receive();

            client.HandleControlMessages();

            Assert.AreEqual(0, clientSession.GetPacketWaitingAcknowledgeCount());

            Session serverSession = server.AcceptPendingSession();

            Message decodedMessage = serverSession.Receive();

            decodedMessage.IsAutoRelease = false;

            String originalMessageString = originalMessage.ToString();
            String decodedMessageString  = decodedMessage.ToString();

            Assert.AreEqual(originalMessageString, decodedMessageString);

            server.Shutdown();

            Thread.Sleep(100);
        }
Example #4
0
        public void Connect(Guid sourceBubbleId, Guid targetBubbleId, String targetHubAddress, int targetHubPort, float targetBubbleX, float targetBubbleY, float targetBubbleZ)
        {
            AttachRequestMessage message = (AttachRequestMessage)MessageFactory.Current.ReserveMessage(typeof(AttachRequestMessage));

            Session session = transmitter.OpenSession(targetHubAddress, targetHubPort, message);

            message.TargetBubbleId = targetBubbleId;

            if (!Bubbles.ContainsKey(sourceBubbleId))
            {
                throw new Exception("No such local bubble: " + sourceBubbleId);
            }

            session.Bubble = Bubbles[sourceBubbleId];

            message.SourceBubbleFragment.BubbleId              = session.Bubble.BubbleId;
            message.SourceBubbleFragment.BubbleName            = session.Bubble.BubbleName;
            message.SourceBubbleFragment.BubbleAssetCacheUrl   = HubAssetCacheUrl;
            message.SourceBubbleFragment.BubbleAddress         = HubAddress;
            message.SourceBubbleFragment.BubblePort            = (uint)HubPort;
            message.SourceBubbleFragment.BubbleCenter.X        = -targetBubbleX;
            message.SourceBubbleFragment.BubbleCenter.Y        = -targetBubbleY;
            message.SourceBubbleFragment.BubbleCenter.Z        = -targetBubbleZ;
            message.SourceBubbleFragment.BubbleRange           = session.Bubble.BubbleRange;
            message.SourceBubbleFragment.BubblePerceptionRange = session.Bubble.BubblePerceptionRange;
            message.SourceBubbleFragment.BubbleRealTime        = 0;

            message.ProgramName            = ProgramName;
            message.ProgramMajorVersion    = ProgramMajorVersion;
            message.ProgramMinorVersion    = ProgramMinorVersion;
            message.ProtocolMajorVersion   = MxpConstants.ProtocolMajorVersion;
            message.ProtocolMinorVersion   = MxpConstants.ProtocolMinorVersion;
            message.ProtocolSourceRevision = MxpConstants.ProtocolSourceRevision;

            session.Send(message);
            //MessageFactory.Current.ReleaseMessage(message);

            sessions.Add(session);
        }