I've created a unix socket in .NET Core on Linux (Ubuntu 16.04):
var unixSocket = "/var/run/mysqld/mysqld.sock";
var socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.IP);
Now how do I connect the socket?
The .NET Core API lists various Socket.Connect options, but all except for the first one deal with IP Addresses:
public void Connect(EndPoint remoteEP)
public void Connect(IPAddress address, int port)
public void Connect(IPAddress[] addresses, int port)
public void Connect(string host, int port)
The System.Net API defines a DNSEndpoint
and an IPEndpoint
, but I can't seem to find a UnixEndpoint
or similar class to pass to Socket.Connect(EndPoint remoteEP)
Update: .NET Standard 2.1 / .NET Core 2.1 contains a UnixDomainSocketEndPoint Class
Original answer, applies to versions of .NET Standard / .NET Core prior to 2.1:
There does not seem to be a built-in
UnixEndPoint
class for .NET Core or a library that implements one at the time of this writing. The UnixEndPoint class from the Mono.Posix project can be easily adapted to work with .NET Core, however:With this class in your project, the socket can be connected like so: