Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Unix Domain Sockets at the client-side? #663

Closed
fukaminakrize opened this issue Nov 18, 2019 · 3 comments
Closed

Support for Unix Domain Sockets at the client-side? #663

fukaminakrize opened this issue Nov 18, 2019 · 3 comments
Labels
question Further information is requested

Comments

@fukaminakrize
Copy link

Hi, grpc-dotnet supports UDS at the server-side. Are there plans for supporting UDS at the client-side ?

Thanks!

@fukaminakrize fukaminakrize added the question Further information is requested label Nov 18, 2019
@JamesNK
Copy link
Member

JamesNK commented Nov 18, 2019

Yes. It will require a planned new feature in .NET 5 - https://github.com/dotnet/corefx/issues/35404

@scalablecory
Copy link

This has been resolved via the API added here in .NET 5: dotnet/runtime#41949

@jsmouret
Copy link

jsmouret commented Nov 26, 2020

TLDR;
https://docs.microsoft.com/en-us/aspnet/core/grpc/interprocess?view=aspnetcore-5.0

using System.Net.Http;
using System.Net.Sockets;
using System.Threading;
using Grpc.Net.Client;

public GrpcChannel ForUnixSocket(string path)
{
	var endpoint = new UnixDomainSocketEndPoint(path);
	return GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions {
		HttpHandler = new SocketsHttpHandler {
			ConnectCallback = async (SocketsHttpConnectionContext _, CancellationToken cancellationToken) => {
				var socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
				try {
					await socket.ConnectAsync(endpoint, cancellationToken).ConfigureAwait(false);
					return new NetworkStream(socket, true);
				} catch {
					socket.Dispose();
					throw;
				}
			}
		}
	});
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants