tesses.broadcast/README.md

2.8 KiB

Tesses.Broadcast

Version Downloads Version Downloads

A simple udp broadcast library

Client

using Tesses.Broadcast;

await foreach(var item in BroadcastClient.ScanAsync("Test",6942,default)) //replace Test with your service name, replace 6942 with desired port used by server, replace default with CancellationToken
{
    Console.WriteLine($"Found device {item.DeviceName} with {item.ServiceUrl} and with ip: {item.Endpoint}");
}

Server

using Tesses.Broadcast;

await new BroadcastServerBuilder()
.WithDeviceName("Mikes Phone") //replace with the server name (any string)
.WithService("Test","http://127.0.0.1:3254/") //127.0.0.1 will be rewriten by client
.WithService("Other Service", "http://127.0.0.1:4949/") //another service my friend
.WithPort(6942) //replace with desired port to listen on
.Build()
.ListenAsync();

Eto

Install this nuget package.

using(var bro = new BroadcastDialog("Test",6942)) //replace Test with your service name, replace 6942 with desired port used by server
{
            serviceUrl.Text=bro.ShowModal(); //will return empty string if cancelled
}

Protocol

Request

Type Name Value Description
char[11] Signature "TessesBcReq" A signature to decern a request from a random udp packet
uint16be NameLength <The Length of Name> The big endian 16 bit, byte length of Name
char[NameLength] Name <The Service Name> The Service Name, Test in the example

Response

Type Name Value Description
char[12] Signature "TessesBcResp" A signature to decern a response from a random udp packet
uint16be DeviceNameLength <The Length of DeviceName> The big endian 16 bit, byte length of DeviceName
char[DeviceNameLength] DeviceName <The Device Name> The Device Name, "Mikes Phone" in this example
uint16be ServiceUrlLength <The Length of ServiceUrl> The big endian 16 bit, byte length of ServiceUrl
char[ServiceUrlLength] ServiceUrl <The Service Url> The Service Url, "http://127.0.0.1:3254/" in this example

Converting the url

If the hostname starts with "127." or equals "localhost" replace the hostname with the remote ip (server ip) (do this on the client)