Ejemplo n.º 1
0
        public async Task SendResponseAsync(uint spaceInx, Stream stream, int length)
        {
            if (stream is MemoryStream)
            {
                if (stream.Position == stream.Length)
                {
                    stream.Position = 0;
                }
            }
            printHelper?.Printline($"응답 전송: {spaceInx}");
            PacketContainer packetContainer = new PacketContainer(DataType.Response, encryptHelper);
            await packetContainer.WriteAsync(spaceInx);

            await packetContainer.WriteAsync(stream, length);

            await writeSemaphoreSlim.WaitAsync();

            try
            {
                await packetContainer.Flush(networkStream);
            }
            finally
            {
                writeSemaphoreSlim.Release();
            }
        }
Ejemplo n.º 2
0
        public async Task SendRequestAsync(string key, Stream stream, int length, ResponseReceiver receiver)
        {
            printHelper?.Printline($"요청 전송: {currentSpaceInx} - {key}");
            PacketContainer packetContainer = new PacketContainer(DataType.Request, encryptHelper);

            if (stream is MemoryStream)
            {
                if (stream.Position == stream.Length)
                {
                    stream.Position = 0;
                }
            }

            var spaceInx = currentSpaceInx++;

            responseReceivers[spaceInx] = receiver;

            await packetContainer.WriteAsync(spaceInx);

            await packetContainer.WriteAsync(key);

            await packetContainer.WriteAsync(stream, length);

            await writeSemaphoreSlim.WaitAsync();

            try
            {
                await packetContainer.Flush(networkStream); //TODO: Handle flush exception!!!
            }
            finally
            {
                writeSemaphoreSlim.Release();
            }
        }
Ejemplo n.º 3
0
        public async Task SendFailedAsync(uint spaceInx, string message)
        {
            printHelper?.Printline($"실패 정보 전송: {spaceInx} - {message}");
            PacketContainer packetContainer = new PacketContainer(DataType.Failed, encryptHelper);
            await packetContainer.WriteAsync(spaceInx);

            await packetContainer.WriteAsync(message);

            await writeSemaphoreSlim.WaitAsync();

            try
            {
                await packetContainer.Flush(networkStream);
            }
            finally
            {
                writeSemaphoreSlim.Release();
            }
        }