public FramedClient(IRawByteClient client) { this.client = client; this.recvBuffer = new ResizableCyclicBuffer(4096); this.client.Received += ClientReceivedData; }
public FramedClient(IRawByteClient client) { this.received = new Subject <ArraySegment <byte> >(); this.client = client; this.recvBuffer = new ResizableCyclicBuffer(4096); this.client.Received.Subscribe(ClientReceivedData); }
public FramedClient(IRawByteClient client) { this.received = new Subject<ArraySegment<byte>>(); this.client = client; this.recvBuffer = new ResizableCyclicBuffer(4096); this.client.Received.Subscribe(ClientReceivedData); }
public RawByteClientStream(IRawByteClient client) { this.disposed = false; this.hasDataEvent = new ManualResetEventSlim(); this.client = client; this.buffer = new ResizableCyclicBuffer(4096); this.client.Received += DataReceived; }
public RawByteClientStream(IRawByteClient client) { this.disposed = false; this.hasDataEvent = new ManualResetEventSlim(); this.client = client; this.buffer = new ResizableCyclicBuffer(4096); this.client.Received.Subscribe(DataReceived); }
/// <summary> /// Initialises ssl client as a client side endpoint. /// </summary> public SslClient(IRawByteClient client, string targetHost, RemoteCertificateValidationCallback remoteCertificateValidationCallback) { Ensure.IsNotNull(client, "client"); Ensure.IsNotNullOrWhiteSpace(targetHost, "targetHost"); InitializeAsClient(client, targetHost, remoteCertificateValidationCallback); }
/// <summary> /// Initialises ssl client as a client side endpoint. /// </summary> public SslClient(IRawByteClient client, string targetHost, bool allowEveryCertificate) { Ensure.IsNotNull(client, "client"); Ensure.IsNotNullOrWhiteSpace(targetHost, "targetHost"); if (allowEveryCertificate) InitializeAsClient(client, targetHost, AllowEveryCertificate); else InitializeAsClient(client, targetHost, null); }
private void InitializeAsServer(IRawByteClient client, X509Certificate certificate) { InitializeCommon(client, isClient: false); this.serverCertificate = certificate; this.clientStreamWrapper = new RawByteClientStream(this.client); this.sslStream = new SslStream( this.clientStreamWrapper, true); }
/// <summary> /// Initialises ssl client as a server side endpoint. /// It is assumed, that passed client is already connected. /// EstablishSsl should be called when this constructor is used. /// </summary> public SslClient(IRawByteClient client, X509Certificate serverCertificate) { Ensure.IsNotNull(client, "client"); Ensure.IsNotNull(serverCertificate, "serverCertificate"); if (!client.IsConnected) throw new InvalidOperationException("Socket client should be connected"); InitializeAsServer(client, serverCertificate); }
/// <summary> /// Initialises ssl client as a server side endpoint. /// It is assumed, that passed client is already connected. /// EstablishSsl should be called when this constructor is used. /// </summary> public SslClient(IRawByteClient client, X509Certificate serverCertificate) { Ensure.IsNotNull(client, "client"); Ensure.IsNotNull(serverCertificate, "serverCertificate"); if (!client.IsConnected) { throw new InvalidOperationException("Socket client should be connected"); } InitializeAsServer(client, serverCertificate); }
/// <summary> /// Initialises ssl client as a client side endpoint. /// </summary> public SslClient(IRawByteClient client, string targetHost, bool allowEveryCertificate) { Ensure.IsNotNull(client, "client"); Ensure.IsNotNullOrWhiteSpace(targetHost, "targetHost"); if (allowEveryCertificate) { InitializeAsClient(client, targetHost, AllowEveryCertificate); } else { InitializeAsClient(client, targetHost, null); } }
private void InitializeCommon(IRawByteClient client, bool isClient) { this.connected = new AsyncSubject <Unit>(); this.disconnected = new AsyncSubject <Exception>(); this.sent = new Subject <int>(); this.received = new Subject <ArraySegment <byte> >(); this.isClient = isClient; this.disconnectCalled = false; this.client = client; this.client.Disconnected.Subscribe(ClientDisconnected); this.client.Connected.Subscribe(_ => ClientConnected()); this.client.Sent.Subscribe(ClientSentData); }
public static byte[] ReceiveData(this IRawByteClient client, int totalExpectedBytes, int timeout, Action sendAction) { var ev = new ManualResetEventSlim(); var buffer = new List <byte>(); client.Received.Subscribe(bs => { lock (buffer) { buffer.AddRange(bs); } }); sendAction(); var sw = Stopwatch.StartNew(); while (true) { lock (buffer) { if (buffer.Count == totalExpectedBytes) { break; } } Thread.Sleep(50); if (sw.ElapsedMilliseconds > timeout) { throw new TimeoutException(); } } lock (buffer) { return(buffer.ToArray()); } }
private void InitializeAsClient(IRawByteClient client, string targetHost, RemoteCertificateValidationCallback remoteCertificateValidationCallback) { InitializeCommon(client, isClient: true); this.targetHost = targetHost; this.clientStreamWrapper = new RawByteClientStream(this.client); #if !MONO this.sslStream = new SslStream( this.clientStreamWrapper, true, remoteCertificateValidationCallback, null, EncryptionPolicy.RequireEncryption); #else this.sslStream = new SslStream( this.clientStreamWrapper, true, remoteCertificateValidationCallback, null); #endif }
/// <summary> /// Initialises ssl client as a client side endpoint. /// </summary> public SslClient(IRawByteClient client, string targetHost) : this(client, targetHost, allowEveryCertificate : false) { }
/// <summary> /// Initialises ssl client as a client side endpoint. /// </summary> public SslClient(IRawByteClient client, string targetHost) : this(client, targetHost, allowEveryCertificate: false) { }
private void InitializeCommon(IRawByteClient client, bool isClient) { this.connected = new AsyncSubject<Unit>(); this.disconnected = new AsyncSubject<Exception>(); this.sent = new Subject<int>(); this.received = new Subject<ArraySegment<byte>>(); this.isClient = isClient; this.disconnectCalled = false; this.client = client; this.client.Disconnected.Subscribe(ClientDisconnected); this.client.Connected.Subscribe(_ => ClientConnected()); this.client.Sent.Subscribe(ClientSentData); }
private void InitializeCommon(IRawByteClient client, bool isClient) { this.connectedTcs = new TaskCompletionSource<int>(); this.isClient = isClient; this.disconnectCalled = false; this.client = client; this.client.Disconnected += ClientDisconnected; this.client.Connected += ClientConnected; this.client.Sent += ClientSentData; }