Lightweight LAN Discovery & Auto-Configuration Library for .NET
SocketLocator is a small but powerful library that allows applications on the same LAN
to automatically detect a server/host machine without configuring static IPs.
It is ideal for:
- POS systems
- Local business networks
- Kiosk systems
- In-store multi-device solutions
- Any LAN-based auto-discovery scenario
SocketLocator uses UDP broadcast discovery with a very small protocol,
making it fast, dependency-free, and extremely easy to integrate.
One of the main goals of SocketLocator is to let POS clients automatically connect
to the main database hosted on a LAN "host" machine.
- The client broadcasts a discovery message.
- The host replies with:
Host IP,DB Port, andHostname. - The client builds its own database connection string using that information.
Example (SQL Server):
var info = await _socketMap.DiscoverAsync();
if (info is null) throw new Exception("Host not found.");
var connectionString =
$"Server={info.Ip},{info.DbPort};Database=POSDB;User Id=sa;Password=StrongPassword;TrustServerCertificate=True;";- Automatic host discovery over LAN
- Zero-configuration for client devices
- Hardware serial number (Volume ID) sent automatically
- Server replies with: Host IP, DB Port, HostName
- Clean abstraction layer for Client + Server
- Real-time event when a new client connects
- Thread-safe device list (ConcurrentDictionary)
- Dependency Injection Ready (AddClientSocketMap / AddSocketServer)
- Works on Console, ASP.NET, Worker Service, WinForms, WPF… everything
- Tiny footprint & no external dependencies
dotnet add package SocketLocatorvar result = await _socketMap.DiscoverAsync();
if(result is not null)
{
Console.WriteLine($"Host IP: {result.Ip}");
Console.WriteLine($"DB Port: {result.DbPort}");
Console.WriteLine($"Hostname: {result.HostName}");
}builder.Services.AddClientSocketMap(options =>
{
options.DiscoveryPort = 50000;
options.RequestMessage = "POS_DISCOVER";
options.ResponsePrefix = "POS_HOST";
});builder.Services.AddSocketServer(options =>
{
options.ConnectionPort = 50000;
options.RequestMessage = "POS_DISCOVER";
options.ResponsePrefix = "POS_HOST";
});var server = app.Services.GetRequiredService<ISocketServer>();
if(server is UdpSocketServer udp)
{
udp.OnSerialAdded += (serial) =>
{
Console.WriteLine($"New Client Detected: {serial}");
};
}public class SocketServerHostedService : BackgroundService
{
private readonly ISocketServer _server;
public SocketServerHostedService(ISocketServer server)
{
_server = server;
}
protected override Task ExecuteAsync(CancellationToken stoppingToken)
=> _server.ListenAsync(stoppingToken);
}POS_DISCOVER|<VOLUME_SERIAL>
POS_HOST|<HOST_IP>|<DB_PORT>|<HOST_NAME>
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddSocketServer(options =>
{
options.ConnectionPort = 50000;
});
builder.Services.AddHostedService<SocketServerHostedService>();
var app = builder.Build();
await app.RunAsync();Ali Zidan Distributed Systems & .NET Developer
Studio Nex Software production