Esempio n. 1
0
        async Task <byte[]> IEasyChannel.SendAsync([NotNull] byte[] buffer, PacketOptions options, int millisecondsTimeout)
        {
            if (buffer is null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }
            ProtocolPacket packet = CreatePacket(buffer, options);

            return(await _easyBase.SendAsync(packet, ConnectOptions.RemoteEndPoint, millisecondsTimeout));
        }
Esempio n. 2
0
 private ProtocolPacket CreatePacket(byte[] buffer, PacketOptions options)
 {
     return(new ProtocolPacket
     {
         Ip = _localEndPoint.Address.GetAddressBytes(),
         Port = _localEndPoint.Port,
         Data = buffer,
         PacketMode = PacketMode.Request,
         IsCompress = options?.CompressBuffer ?? false,
         HasResponse = options?.HasResponse ?? true
     });
 }
Esempio n. 3
0
 public async Task SendAsync([NotNull] byte[] buffer, PacketOptions options, int millisecondsTimeout = -1)
 {
     if (buffer is null)
     {
         throw new ArgumentNullException(nameof(buffer));
     }
     _basePacket.Data        = buffer;
     _basePacket.PacketMode  = PacketMode.Request;
     _basePacket.HasResponse = options?.HasResponse ?? true;
     _basePacket.IsCompress  = options?.CompressBuffer ?? false;
     await _sendFunc.Invoke(_basePacket, millisecondsTimeout);
 }
Esempio n. 4
0
        private ProtocolPacket CreatePacket(byte[] buffer, PacketOptions options)
        {
            ProtocolPacket packet = new ProtocolPacket
            {
                Ip            = ((IPEndPoint)_tcpClient.Client.LocalEndPoint).Address.GetAddressBytes(),
                Port          = ((IPEndPoint)_tcpClient.Client.LocalEndPoint).Port,
                Data          = buffer,
                PacketMode    = PacketMode.Request,
                IsCompress    = options?.CompressBuffer ?? false,
                HasResponse   = options?.HasResponse ?? true,
                ReportArrived = false
            };

            return(packet);
        }
Esempio n. 5
0
        async Task <byte[]> IEasyHost.SendAsync([NotNull] byte[] buffer, PacketOptions options, int millisecondsTimeout)
        {
            if (buffer is null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            ProtocolPacket packet = CreatePacket(buffer, options);

            _tcpChannels.Keys.AsParallel().ForAll(async i =>
            {
                await i._easyBase.SendAsync(packet, ConnectOptions.RemoteEndPoint, millisecondsTimeout);
            });

            return(await Task.FromResult(new byte[0]));
        }