コード例 #1
0
ファイル: EasyTcp.cs プロジェクト: ismyhy/Plugins.ToolKits
        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));
        }
コード例 #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
     });
 }
コード例 #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);
 }
コード例 #4
0
ファイル: EasyTcp.cs プロジェクト: ismyhy/Plugins.ToolKits
        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);
        }
コード例 #5
0
ファイル: EasyTcp.cs プロジェクト: ismyhy/Plugins.ToolKits
        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]));
        }