Connect Client to EventStoreDB

152 Views Asked by At

I was trying to connect 2 PC's in the same network, the first PC already has EventStoreDB server installed in version 23.6 and in the other PC I have created a console application in .NET, but when I try to read the events in the stream I get this exception:

Grpc.Core.RpcException
  HResult=0x80131500
  Message = Status(StatusCode="Unavailable", Detail="Error starting gRPC call. HttpRequestException: Unable to establish a connection as the target computer expressly denied the connection. (192.168.0.14:2113) SocketException: Unable to establish a connection as the target computer expressly denied the connection.", DebugException="System.Net.Http.Http.HttpRequestException: Unable to establish a connection as the target computer expressly denied the connection. (192.168.0.14:2113)
 ---> System.Net.Sockets.SocketException (10061): A connection cannot be established as the target computer expressly denied such a connection.
 at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
   at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|277_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.AddHttp2ConnectionAsync(HttpRequestMessage request)
   at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.GetHttp2ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at Grpc.Net.Client.Internal.GrpcCall`2.RunCall(HttpRequestMessage request, Nullable`1 timeout)")
  Origen = EventStore.Client
  Seguimiento de la pila:
   en EventStore.Client.Interceptors.TypedExceptionInterceptor.<AsyncUnaryCall>b__5_0[TRequest,TResponse](Task`1 t)
   en System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   en System.Threading.Tasks.Task.<>c.<.cctor>b__272_0(Object obj)
   en System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- Fin del seguimiento de la pila de la ubicación anterior ---
   en System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
   en System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- Fin del seguimiento de la pila de la ubicación anterior ---
   en EventStore.Client.GrpcServerCapabilitiesClient.<GetAsync>d__2.MoveNext()
   en EventStore.Client.EventStoreClientBase.<GetChannelInfoExpensive>d__12.MoveNext()
   en EventStore.Client.SharingProvider`2.<FillBoxAsync>d__10.MoveNext()
   en EventStore.Client.TaskExtensions.<WithCancellation>d__0`1.MoveNext()
   en EventStore.Client.TaskExtensions.<WithCancellation>d__0`1.MoveNext()
   en EventStore.Client.EventStoreClientBase.<GetChannelInfo>d__13.MoveNext()
   en EventStore.Client.EventStoreClientBase.<GetChannelInfo>d__13.MoveNext()
   en EventStore.Client.EventStoreClient.<>c__DisplayClass27_0.<<ReadStreamAsync>b__0>d.MoveNext()
   en EventStore.Client.EventStoreClient.ReadStreamResult.<>c__DisplayClass19_0.<<-ctor>g__PumpMessages|0>d.MoveNext()
   en System.Threading.Channels.AsyncOperation`1.GetResult(Int16 token)
   en System.Threading.Channels.ChannelReader`1.<ReadAllAsync>d__12.MoveNext()
   en System.Threading.Channels.ChannelReader`1.<ReadAllAsync>d__12.System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult(Int16 token)
   en EventStore.Client.EventStoreClient.ReadStreamResult.<GetAsyncEnumerator>d__20.MoveNext()
   en EventStore.Client.EventStoreClient.ReadStreamResult.<GetAsyncEnumerator>d__20.MoveNext()
   en EventStore.Client.EventStoreClient.ReadStreamResult.<GetAsyncEnumerator>d__20.System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult(Int16 token)
   en System.Runtime.CompilerServices.ValueTaskAwaiter`1.GetResult()
   en Program.<Main>d__0.MoveNext() en C:\Users\Yader Barahona\source\repos\ES_Consola\ES_Consola\Program.cs: línea 36
   en Program.<Main>d__0.MoveNext() en C:\Users\Yader Barahona\source\repos\ES_Consola\ES_Consola\Program.cs: línea 36

I have already verified that the server is running on the PC where it is installed, the IP is correct along with the port 2113 and even the firewall is disabled. On the same PC where I have the server it works but when I try this it does not.

Here's the code:

    var settings = EventStoreClientSettings.Create("esdb://192.168.0.14:2113?tls=false");
    settings.DefaultCredentials = new UserCredentials("admin", "changeit");

    var client = new EventStoreClient(settings);

    var streamName = "shopping_cart_stream"; 

    var subscription = client.SubscribeToStreamAsync(
        streamName,
        FromStream.Start,
        async (subscription, @event, cancellationToken) =>
        {
            var eventType = @event.Event.EventType;
            var eventData = Encoding.UTF8.GetString(@event.Event.Data.ToArray());
            var eventMessage = $"EventType: {eventType}, Data: {eventData}";

            Console.WriteLine(eventMessage);
        }
    );

    var events = client.ReadStreamAsync(
        Direction.Forwards,
        streamName,
        StreamPosition.Start);

    await foreach (var @event in events)
    {
        var eventData = Encoding.UTF8.GetString(@event.Event.Data.ToArray());
        Console.WriteLine(eventData);
    }
}
0

There are 0 best solutions below