コード例 #1
0
        // 모든 클라이언트로 BroadCast~!~!
        public void BroadCast()
        {
            int msgCount = 0;
            int msgSize  = 0;

            lock (_sendQueue)
            {
                msgCount = _sendQueue.Count;

                // 메시지가 있으면 변환해줘야함.
                if (msgCount != 0)
                {
                    msgSize = _messageTransfer.MsgsToSendData(_sendQueue.Dequeue(), _sendDataBuffer, 0, _sendDataBuffer.Length);
                }
                // msgSize = _messageTransfer.MsgsToByte(_sendQueue.Dequeue(), _sendDataBuffer);
            }

            lock (_clientList)
            {
                // 보낼 클라이언트가 있는지 확인.
                if (_clientList.Count == 0)
                {
                    return;
                }

                for (int i = 0; i < _clientList.Count; ++i)
                {
                    // 보낼 msg가있다면, 각 클라이언트마다 Broadcast msg 전달.
                    if (msgSize != 0)
                    {
                        _clientList[i].SetBroadcastData(_sendDataBuffer, msgSize, msgCount);
                    }

                    // Broadcast msg가 전달 되었으면, send 실행.
                    _clientList[i].StartSendData();
                }
            }

            // 데이터 보내고 초기화.
            Array.Clear(_sendDataBuffer, 0, _sendDataBuffer.Length);
        }
コード例 #2
0
ファイル: ClientData.cs プロジェクト: gangjung/CruNetworkDll
        // Unicast Data 설정. 해당 클라이언트만 받는 정보.
        // 보내기 직전에 실행된다.
        public void SetUnicastData()
        {
            int count = 0;

            lock (_sendQueue)
            {
                count = _sendQueue.Count;

                if (_sendQueue.Count == 0)
                {
                    return;
                }

                _unicastDataSize = _transfer.MsgsToSendData(_sendQueue.Dequeue(), _unicastBuffer, 0, _unicastBuffer.Length);
                //_unicastDataSize = _transfer.MsgsToByte(_sendQueue.Dequeue(), _unicastBuffer);
            }

            Array.Copy(_unicastBuffer, _headSize, _sendBuffer, _sendDataSize + _headSize, _unicastDataSize - _headSize);
            _sendDataSize  += _unicastDataSize - _headSize;
            _sendDataCount += count;
        }