Beispiel #1
0
    private NetworkOutMessage CreateMessage(byte MessageType)
    {
        NetworkOutMessage msg = serverConnection.CreateMessage(MessageType);

        msg.Write(MessageType);
        // Add the local userID so that the remote clients know whose message they are receiving
        msg.Write(localUserID);
        return(msg);
    }
 void AppendBoolean(NetworkOutMessage msg, bool boolean)
 {
     if (boolean)
     {
         Debug.Log(1.0f);
         msg.Write(1.0f);
     }
     else
     {
         Debug.Log(0.0f);
         msg.Write(0.0f);
     }
 }
Beispiel #3
0
    /// <summary>
    /// 广播cube的message
    /// </summary>
    /// <param name="positon"></param>
    ///


    public void SendCubePosition(Vector3 positon)
    {
        if (serverConnection != null && serverConnection.IsConnected())
        {
            NetworkOutMessage msg = CreateMessage((byte)CustomMessageID.CubePostion);

            msg.Write(positon.x);
            msg.Write(positon.y);
            msg.Write(positon.z);

            serverConnection.Broadcast(msg, MessagePriority.Immediate, MessageReliability.ReliableOrdered, MessageChannel.Default);
        }
    }
    void AppendDateTime(NetworkOutMessage msg, DateTime date)
    {
        int hour = date.Hour;
        int min  = date.Minute;
        int sec  = date.Second;
        int msec = date.Millisecond;

        msg.Write(hour);
        msg.Write(min);
        msg.Write(sec);
        msg.Write(msec);

        Debug.Log(hour + ":" + min + ":" + min + "." + msec);
    }
 void AppendStageTransform(NetworkOutMessage msg, Vector3 position, Quaternion rotation, Vector3 Scale, bool render)
 {
     AppendVector3(msg, position);
     AppendQuaternion(msg, rotation);
     AppendVector3(msg, Scale);
     if (render)
     {
         msg.Write(1.0f);
     }
     else
     {
         msg.Write(0.0f);
     }
 }
Beispiel #6
0
    /// <summary>
    /// Sends the Kinect processed depth frame.
    /// Since depth is floating point numbers, the message
    /// needs to be divided into two.
    /// </summary>
    /// <param name="depthData"> array of depth data </param>
    public void SendDepthData(ushort[] depthData)
    {
        // If we are connected to a session, broadcast our info
        if (this.serverConnection != null && this.serverConnection.IsConnected())
        {
            int length = depthData.Length;
            int offset = 0;
            if ((2 * length) > MAX_PACKET_SIZE) // Will need to divide depth data into at least two messages
            {
                offset = (int)Math.Ceiling((float)(length) / 2f);
            }
            // Start first message
            // 1) Start with UserMessageIDStart
            NetworkOutMessage msg1 = CreateMessage((int)TestMessageID.StartID);
            // 2) Add message type ID
            msg1.Write((int)MsgID.DEPTH1);
            // 3) Add message length
            msg1.Write(offset);
            for (int i = 0; i < offset; i++)
            {
                msg1.Write(depthData[i]);
            }
            // Send the message as a broadcast
            this.serverConnection.Broadcast(
                msg1,
                MessagePriority.Immediate,
                MessageReliability.UnreliableSequenced,
                MessageChannel.Avatar);

            // Start second message
            // 1) Start with UserMessageIDStart
            NetworkOutMessage msg2 = CreateMessage((int)TestMessageID.StartID);
            // 2) Add message type ID
            msg2.Write((int)MsgID.DEPTH2);
            // 3) Add message length
            msg2.Write(length - offset);
            // 4) Add message
            for (int i = offset; i < length; i++)
            {
                msg2.Write(depthData[i]);
            }
            // Send the message as a broadcast
            this.serverConnection.Broadcast(
                msg2,
                MessagePriority.Immediate,
                MessageReliability.UnreliableSequenced,
                MessageChannel.Avatar);
        }
    }
Beispiel #7
0
    public void SendTempTargetWithImage(byte[] imageBytes, float temp)
    {
        if (serverConnection != null && serverConnection.IsConnected())
        {
            NetworkOutMessage msg = CreateMessage((byte)CustomMessageID.IRImage);

            msg.Write(temp);

            msg.Write(imageBytes.Length);

            msg.WriteArray(imageBytes, Convert.ToUInt32(imageBytes.Length));

            serverConnection.Broadcast(msg, MessagePriority.Immediate, MessageReliability.ReliableOrdered, MessageChannel.Default);
        }
    }
Beispiel #8
0
    public void SendIRImageByString(byte[] imageBytes)
    {
        if (serverConnection != null && serverConnection.IsConnected())
        {
            NetworkOutMessage msg = CreateMessage((byte)CustomMessageID.IRImage);

            msg.Write(imageBytes.Length);

            XString tempString = new XString(System.Text.Encoding.UTF8.GetString(imageBytes));

            msg.Write(tempString);

            serverConnection.Broadcast(msg, MessagePriority.Immediate, MessageReliability.UnreliableSequenced, MessageChannel.Default);
        }
    }
    private NetworkOutMessage CreateMessage(byte MessageType)
    {
        NetworkOutMessage msg = serverConnection.CreateMessage(MessageType);

        msg.Write(MessageType);
        return(msg);
    }
        public void SendTPPCNetworkTime(long time)
        {
            if (this.serverConnection != null && this.serverConnection.IsConnected() && HolographicCameraManager.Instance != null)
            {
                // Create an outgoing network message to contain all the info we want to send
                NetworkOutMessage msg = CreateMessage((byte)TestMessageID.SetNetworkTime);
                msg.Write(time);

#if UNITY_EDITOR
                if (HolographicCameraManager.Instance == null ||
                    HolographicCameraManager.Instance.tppcUser == null ||
                    !HolographicCameraManager.Instance.tppcUser.IsValid())
                {
                    // Send the message as a broadcast, which will cause the server to forward it to all other users in the session.
                    serverConnection.Broadcast(
                        msg,
                        MessagePriority.Immediate,
                        MessageReliability.UnreliableSequenced,
                        MessageChannel.Avatar);
                }
                else
                {
                    // We have a known tppc user, only send the offset time to that device.
                    serverConnection.SendTo(
                        HolographicCameraManager.Instance.tppcUser,
                        ClientRole.Primary,
                        msg,
                        MessagePriority.Immediate,
                        MessageReliability.UnreliableSequenced,
                        MessageChannel.Avatar);
                }
#endif
            }
        }
        public void SendTPPCColorDuration(long duration)
        {
#if UNITY_EDITOR
            if (this.serverConnection != null && this.serverConnection.IsConnected() && HolographicCameraManager.Instance != null && SharingStage.Instance.SessionUsersTracker != null)
            {
                if (SharingStage.Instance == null || SharingStage.Instance.SessionUsersTracker.CurrentUsers.Count <= 1)
                {
                    return;
                }

                if (HolographicCameraManager.Instance != null &&
                    HolographicCameraManager.Instance.tppcUser != null &&
                    HolographicCameraManager.Instance.tppcUser.IsValid())
                {
                    // Create an outgoing network message to contain all the info we want to send
                    NetworkOutMessage msg = CreateMessage((byte)TestMessageID.SetColorDuration);
                    msg.Write(duration);

                    // We have a known tppc user, only send the offset time to that device.
                    serverConnection.SendTo(
                        HolographicCameraManager.Instance.tppcUser,
                        ClientRole.Primary,
                        msg,
                        MessagePriority.Immediate,
                        MessageReliability.UnreliableSequenced,
                        MessageChannel.Avatar);
                }
            }
#endif
        }
Beispiel #12
0
    /// <summary>
    /// 发送image的array
    /// </summary>
    /// <param name="imageBytes"></param>
    public void SendIRImage(byte[] imageBytes)
    {
        if (serverConnection != null && serverConnection.IsConnected())
        {
            NetworkOutMessage msg = CreateMessage((byte)CustomMessageID.IRImage);

            msg.Write(imageBytes.Length);

            for (int i = 0; i < imageBytes.Length; i++)
            {
                msg.Write(imageBytes[i]);
            }

            serverConnection.Broadcast(msg, MessagePriority.Immediate, MessageReliability.UnreliableSequenced, MessageChannel.Default);
        }
    }
    /// <summary>
    /// Sends the Kinect processed RGB32.
    /// Ignores the alpha channel.
    /// </summary>
    /// <param name="colorData"> array of color data in RGB32 </param>
    public void SendColorData(byte[] colorData)
    {
        // If we are connected to a session, broadcast our info
        if (this.serverConnection != null && this.serverConnection.IsConnected())
        {
            // RED message
            NetworkOutMessage rMsg = CreateMessage((int)TestMessageID.StartID);
            rMsg.Write((byte)MsgID.RED);
            rMsg.Write(colorData.Length / BYTES_PER_PIXEL);

            // GREEN message
            NetworkOutMessage gMsg = CreateMessage((int)TestMessageID.StartID);
            gMsg.Write((byte)MsgID.GREEN);
            gMsg.Write(colorData.Length / BYTES_PER_PIXEL);

            // BLUE message
            NetworkOutMessage bMsg = CreateMessage((int)TestMessageID.StartID);
            bMsg.Write((byte)MsgID.BLUE);
            bMsg.Write(colorData.Length / BYTES_PER_PIXEL);

            // 4) Add message
            for (int i = 0; i < colorData.Length; i += BYTES_PER_PIXEL)
            {
                rMsg.Write(colorData[i + 0]);
                gMsg.Write(colorData[i + 1]);
                bMsg.Write(colorData[i + 2]);
                // ignore alpha channel
            }

            // Send the message as a broadcast
            this.serverConnection.Broadcast(
                rMsg,
                MessagePriority.Immediate,
                MessageReliability.UnreliableSequenced,
                MessageChannel.Avatar);
            this.serverConnection.Broadcast(
                gMsg,
                MessagePriority.Immediate,
                MessageReliability.UnreliableSequenced,
                MessageChannel.Avatar);
            this.serverConnection.Broadcast(
                bMsg,
                MessagePriority.Immediate,
                MessageReliability.UnreliableSequenced,
                MessageChannel.Avatar);
        }
    }
Beispiel #14
0
    private NetworkOutMessage CreateMessage(byte messageType, string msgKey, IReadOnlyCollection <float> values)
    {
        NetworkOutMessage msg = _serverConnection.CreateMessage(messageType);

        msg.Write(messageType);
        msg.Write(LocalUserId);

        msg.Write(msgKey);
        msg.Write(values.Count);

        foreach (var value in values)
        {
            msg.Write(value);
        }

        return(msg);
    }
        // Append a network message with IP Byte Size and Byte array for IP.
        void AppendIP(NetworkOutMessage msg, string IP)
        {
            byte[] ipBytes  = System.Text.Encoding.ASCII.GetBytes(IP);
            long   byteSize = (long)ipBytes.Length;

            msg.Write(byteSize);
            msg.WriteArray(ipBytes, (uint)byteSize);
        }
Beispiel #16
0
    // string
    void AddVal(NetworkOutMessage msg, string value)
    {
        byte[] strBytes = System.Text.Encoding.ASCII.GetBytes(value);
        long   byteSize = (long)strBytes.Length;

        msg.Write(byteSize);
        msg.WriteArray(strBytes, (uint)byteSize);
    }
    // 将Cube位置广播给其他用户
    public void SendCubePosition(Vector3 position, MessageReliability?reliability = MessageReliability.ReliableOrdered)
    {
        if (serverConnection != null && serverConnection.IsConnected())
        {
            // 将Cube的位置写入消息
            NetworkOutMessage msg = CreateMessage((byte)CustomMessageID.CubePosition);

            msg.Write(position.x);
            msg.Write(position.y);
            msg.Write(position.z);

            // 将消息广播给其他人
            serverConnection.Broadcast(msg,
                                       MessagePriority.Immediate, //立即发送
                                       reliability.Value,         //可靠排序数据包
                                       MessageChannel.Default);   // 默认频道
        }
    }
    private NetworkOutMessage CreateMessage(byte MessageType)
    {
        NetworkOutMessage msg = serverConnection.CreateMessage(MessageType);

        msg.Write(MessageType);
        // Add the local userID so that the remote clients know whose message they are receiving
        //msg.Write(localUserID); // TODO Is this necessary if using one hololens?
        return(msg);
    }
Beispiel #19
0
    public void SendIRImageByLinescan(byte[] imageBytes, Int32 scanIndex)
    {
        if (serverConnection != null && serverConnection.IsConnected())
        {
            NetworkOutMessage msg = CreateMessage((byte)CustomMessageID.IRImage);

            //send the current scan index
            msg.Write(scanIndex);

            //send length data
            msg.Write(imageBytes.Length);

            Debug.Log("sent bytes: " + imageBytes.Length);
            //send image
            msg.WriteArray(imageBytes, Convert.ToUInt32(imageBytes.Length));

            serverConnection.Broadcast(msg, MessagePriority.Immediate, MessageReliability.ReliableOrdered, MessageChannel.Default);
        }
    }
Beispiel #20
0
    public void SendEnemyHit(long enemyId, int amt)
    {
        if (!IsConnected())
        {
            return;
        }
        // Create an outgoing network message to contain all the info we want to send
        NetworkOutMessage msg = CreateMessage((byte)GameMessageID.EnemyHit);

        msg.Write(enemyId);
        msg.Write(amt);

        // Send the message as a broadcast, which will cause the server to forward it to all other users in the session.
        this.serverConnection.Broadcast(
            msg,
            MessagePriority.Medium,
            MessageReliability.ReliableOrdered,
            MessageChannel.Avatar);
    }
Beispiel #21
0
    private NetworkOutMessage CreateMessage(byte commandType)
    {
        NetworkOutMessage msg = serverConnection.CreateMessage(commandType);

        msg.Write(commandType);

        AppendUserData(msg, LocalUserData);

        return(msg);
    }
Beispiel #22
0
    public void SendInstantiateModel(string name, Guid uid)
    {
        // If we are connected to a session
        if (this.serverConnection != null && this.serverConnection.IsConnected())
        {
            // Create an outgoing network message to contain all the info we want to send
            NetworkOutMessage msg = CreateMessage((byte)HoloPaintMessageID.InstantiateModel);

            msg.Write(name);
            msg.Write(uid.ToString());

            // Send the message as a broadcast, which will cause the server to forward it to all other users in the session.
            this.serverConnection.Broadcast(
                msg,
                MessagePriority.Immediate,
                MessageReliability.ReliableOrdered,
                MessageChannel.Default);
        }
    }
Beispiel #23
0
        public void SendModelDelete(BoundingBoxId boundingBoxId)
        {
            // If we are connected to a session, broadcast the bounding box transform
            if (serverConnection != null && serverConnection.IsConnected())
            {
                // Create an outgoing network message to contain all the info we want to send
                NetworkOutMessage msg = CreateMessage((byte)TestMessageID.ModelDelete);

                msg.Write(boundingBoxId.UserId);
                msg.Write(boundingBoxId.BoxId);

                // Send the message as a broadcast, which will cause the server to forward it to all other users in the session.
                serverConnection.Broadcast(
                    msg,
                    MessagePriority.Immediate,
                    MessageReliability.UnreliableSequenced,
                    MessageChannel.Default);
            }
        }
Beispiel #24
0
        public void SendToggleHighlightMessage(string modelName, bool isLocked)
        {
            if (this.serverConnection != null && this.serverConnection.IsConnected())
            {
                NetworkOutMessage msg = CreateMessage((byte)TestMessageID.ToggleHighLight);
                msg.Write(modelName);

                // We can't directly write bools to the message so we have to write bytes
                msg.Write(isLocked ? (byte)1 : (byte)0);

                // Send the message as a broadcast, which will cause the server to forward it to all other users in the session.
                this.serverConnection.Broadcast(
                    msg,
                    MessagePriority.Immediate,
                    MessageReliability.ReliableOrdered,
                    MessageChannel.Avatar);

                Debug.Log("Toggle highlight message for '" + modelName + "' was sent");
            }
        }
Beispiel #25
0
    //Carla: Test to send data to AvatarSourceView for Haptic feedback
    public void SendThresholdData(ulong trackingID, double thresholdData)
    {
        // If we are connected to a session, broadcast our info
        Debug.Log("SendThresholdata");

        if (this.serverConnection != null && this.serverConnection.IsConnected())
        {
            NetworkOutMessage msg = CreateMessage((byte)TestMessageID.BodyData);

            msg.Write((long)trackingID);
            msg.Write(thresholdData);

            // Send the message as a broadcast
            this.serverConnection.Broadcast(
                msg,
                MessagePriority.Immediate,
                MessageReliability.UnreliableSequenced,
                MessageChannel.Avatar);
        }
    }
Beispiel #26
0
    public void SendRemoteUserReceiveDamage(long remoteUserId, int damage)
    {
        if (!IsConnected())
        {
            return;
        }

        // Create an outgoing network message to contain all the info we want to send
        NetworkOutMessage msg = CreateMessage((byte)GameMessageID.RemoteUserRecieveDamage);

        msg.Write(remoteUserId);
        msg.Write(damage);

        // Send the message as a broadcast, which will cause the server to forward it to all other users in the session.
        this.serverConnection.Broadcast(
            msg,
            MessagePriority.Immediate,
            MessageReliability.Reliable,
            MessageChannel.Avatar);
    }
        public void SendUnityUserID(long localUserID)
        {
            // If we are connected to a session, broadcast our head info
            if (this.serverConnection != null && this.serverConnection.IsConnected() && HolographicCameraManager.Instance != null)
            {
                // Create an outgoing network message to contain all the info we want to send
                NetworkOutMessage msg = CreateMessage((byte)TestMessageID.EditorUser);
                uint byteSize         = (uint)HolographicCameraManager.Instance.localIPBytes.Length;
                msg.Write(byteSize);
                msg.WriteArray(HolographicCameraManager.Instance.localIPBytes, byteSize);
                msg.Write(localUserID);

                // Send the message as a broadcast, which will cause the server to forward it to all other users in the session.
                this.serverConnection.Broadcast(
                    msg,
                    MessagePriority.Immediate,
                    MessageReliability.Reliable,
                    MessageChannel.Avatar);
            }
        }
        public void SendShareSticky(Vector3 position, string message, int colorIndex)
        {
            // If we are connected to a session, broadcast our head info
            if (serverConnection != null && serverConnection.IsConnected())
            {
                // Create an outgoing network message to contain all the info we want to send
                NetworkOutMessage msg = CreateMessage((byte)TestMessageID.SharedSticky);

                AppendVector3(msg, position);
                msg.Write(message);
                msg.Write(colorIndex);

                // Send the message as a broadcast, which will cause the server to forward it to all other users in the session.
                serverConnection.Broadcast(
                    msg,
                    MessagePriority.Immediate,
                    MessageReliability.UnreliableSequenced,
                    MessageChannel.Avatar);
            }
        }
Beispiel #29
0
    public void SendTempTarget(float temp)
    {
        if (serverConnection != null && serverConnection.IsConnected())
        {
            NetworkOutMessage msg = CreateMessage((byte)CustomMessageID.IRImage);

            msg.Write(temp);
            Debug.Log("sending temp");

            serverConnection.Broadcast(msg, MessagePriority.Immediate, MessageReliability.ReliableOrdered, MessageChannel.Default);
        }
    }
        public void SendSafeSignal(long playerID)
        {
            NetworkOutMessage msg = CreateMessage((byte)TestMessageID.SafeSignal);

            msg.Write(playerID);

            serverConnection.Broadcast(
                msg,
                MessagePriority.Immediate,
                MessageReliability.UnreliableSequenced,
                MessageChannel.Avatar);
        }