Exemplo n.º 1
0
        public void ClientRecieveTransmission(int transmissionId, byte[] recBuffer)
        {
            // Already completely received or not prepared?
            if (!clientTransmissionData.ContainsKey(transmissionId))
            {
                return;
            }

            // Copy received data into prepared array and remember current dataposition
            DataController.TransmissionData dataToReceive = clientTransmissionData[transmissionId];
            System.Array.Copy(recBuffer, 0, dataToReceive.data, dataToReceive.curDataIndex, recBuffer.Length);
            dataToReceive.curDataIndex += recBuffer.Length;

            if (null != OnDataFragmentReceived)
            {
                OnDataFragmentReceived(transmissionId, recBuffer);
            }

            if (dataToReceive.curDataIndex < dataToReceive.data.Length - 1)
            {
                // Current data not completely received
                return;
            }

            // Current data completely received
            //Debug.Log("Completely Received Data at transmissionId=" + transmissionId);
            clientTransmissionData.Remove(transmissionId);

            if (null != OnDataCompletelyReceived)
            {
                OnDataCompletelyReceived.Invoke(transmissionId, dataToReceive.data);
            }
        }
Exemplo n.º 2
0
        public void ClientPrepareToRecieveTransmission(int transmissionId, int expectedSize, Vector3 centralCarPos)
        {
            if (clientTransmissionData.ContainsKey(transmissionId))
            {
                return;
            }

            if (null != OnTransmissionPreparation)
            {
                OnTransmissionPreparation.Invoke(centralCarPos);
            }

            // Prepare data array which will be filled chunk by chunk by the received data
            DataController.TransmissionData receivingData = new DataController.TransmissionData(new byte[expectedSize]);
            clientTransmissionData.Add(transmissionId, receivingData);
        }
Exemplo n.º 3
0
        public IEnumerator <float> SendBytesToClientsRoutine(int transmissionId, byte[] data, Vector3 centralCarPos)
        {
            SendToPeer(SenderPeer).ClientPrepareToRecieveTransmission(transmissionId, data.Length, centralCarPos);
            yield return(0f);

            serverTransmissionIds.Add(transmissionId);
            DataController.TransmissionData dataToTransmit = new DataController.TransmissionData(data);
            int bufferSize = DataController.Instance.defaultBufferSize;

            while (dataToTransmit.curDataIndex < dataToTransmit.data.Length - 1)
            {
                int remaining = dataToTransmit.data.Length - dataToTransmit.curDataIndex;

                if (remaining < bufferSize)
                {
                    bufferSize = remaining;
                }

                byte[] buffer = new byte[bufferSize];
                System.Array.Copy(dataToTransmit.data, dataToTransmit.curDataIndex, buffer, 0, bufferSize);

                SendToPeer(SenderPeer).ClientRecieveTransmission(transmissionId, buffer);
                dataToTransmit.curDataIndex += bufferSize;

                yield return(0f);

                if (null != OnDataFragmentSent)
                {
                    OnDataFragmentSent.Invoke(transmissionId, buffer);
                }
            }

            // Transmission complete.
            serverTransmissionIds.Remove(transmissionId);

            if (null != OnDataComepletelySent)
            {
                OnDataComepletelySent.Invoke(transmissionId, dataToTransmit.data);
            }
        }