Task IServerTcpHybridConnectionServer.WriteAsync(Guid streamId, Guid id, byte[] data, int offset, int count)
        {
            lock (_syncRoot)
            {
                HybridConnectionStream stream = null;
                if (!_hybridConnectionStreams.TryGetValue(streamId, out stream))
                {
                    _logger.LogError($"Hybrid connection stream not available for connection {_connectionName}");
                    return(Task.Delay(0));
                }

                var memstream = new MemoryStream();
                var tmp       = id.ToByteArray();
                memstream.Write(tmp, 0, tmp.Length);
                tmp = BitConverter.GetBytes((Int32)count);
                memstream.Write(tmp, 0, tmp.Length);
                memstream.Write(data, offset, count);
                tmp = memstream.ToArray();
                stream.Write(tmp, 0, tmp.Length);
                stream.Flush();
                return(Task.Delay(0));
            }
        }
コード例 #2
0
        void IClientTcpMultiplexer.Mutliplex(Guid tcpProxyId, int remotePort, byte[] data, int offset, int count)
        {
            CreateConnection();

            using (var memstream = new MemoryStream())
            {
                var tmp = BitConverter.GetBytes(ControlCommands.Forward);
                memstream.Write(tmp, 0, tmp.Length);
                tmp = tcpProxyId.ToByteArray();
                memstream.Write(tmp, 0, tmp.Length);
                tmp = BitConverter.GetBytes((Int32)remotePort);
                memstream.Write(tmp, offset, tmp.Length);
                tmp = BitConverter.GetBytes((Int32)count);
                memstream.Write(tmp, 0, tmp.Length);
                memstream.Write(data, offset, count);

                lock (_syncRoot)
                {
                    tmp = memstream.ToArray();
                    _hybridConnectionStream.Write(tmp, 0, tmp.Length);
                    _hybridConnectionStream.Flush();
                }
            }
        }