using Devolutions.IronRdp;
using Devolutions.IronRdp.Connector;
class Program
{
static async Task Main(string[] args)
{
// Configure connection
var config = new ConnectorConfig
{
Username = "user",
Password = "password",
Domain = null,
ServerAddr = "server.example.com:3389",
DesktopWidth = 1920,
DesktopHeight = 1080,
EnableTls = true,
EnableCredssp = true,
};
// Create connector
using var connector = new RdpConnector(config);
// Establish connection
var result = await connector.ConnectAsync();
Console.WriteLine($"Connected! Desktop: {result.DesktopWidth}x{result.DesktopHeight}");
// Process session
await ProcessSessionAsync(connector, result);
}
static async Task ProcessSessionAsync(RdpConnector connector, ConnectionResult result)
{
var session = new ActiveSession(result);
var image = new DecodedImage(result.DesktopWidth, result.DesktopHeight);
while (true)
{
var pdu = await connector.ReadPduAsync();
var outputs = session.Process(image, pdu);
foreach (var output in outputs)
{
switch (output.Type)
{
case OutputType.GraphicsUpdate:
// Image has been updated
RenderImage(image);
break;
case OutputType.ResponseFrame:
await connector.WriteAsync(output.Data);
break;
case OutputType.Terminate:
Console.WriteLine("Session terminated");
return;
}
}
}
}
static void RenderImage(DecodedImage image)
{
var pixels = image.GetPixels();
// Render to screen, save to file, etc.
}
}