AK.F1.Timing.Live.IO.LiveMessageStreamEndpoint.OpenStream C# (CSharp) Method

OpenStream() public method

public OpenStream ( ) : IMessageStream
return IMessageStream
        public IMessageStream OpenStream()
        {
            var endpoint = ResolveStreamEndpoint();
            var socket = new Socket(endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

            Log.InfoFormat("connecting: {0}", endpoint);

            try
            {
                socket.Connect(endpoint);
                Log.Info("connected");
                return new LiveSocketMessageStream(socket);
            }
            catch(SocketException exc)
            {
                ((IDisposable)socket).Dispose();
                Log.ErrorFormat("unable to connect to {0}: {1}", endpoint, exc.Message);
                throw Guard.LiveMessageStreamEndpoint_FailedToOpenStream(exc);
            }
        }

Usage Example

        public void can_open_stream()
        {
            var endpoint = new LiveMessageStreamEndpoint();

            using(var stream = endpoint.OpenStream())
            {
                Assert.NotNull(stream);
            }
        }
All Usage Examples Of AK.F1.Timing.Live.IO.LiveMessageStreamEndpoint::OpenStream