Skip to content

Instantly share code, notes, and snippets.

@annagapuz
Last active May 15, 2024 14:10
Show Gist options
  • Save annagapuz/0911d65f809a5147e63b0e579229ade2 to your computer and use it in GitHub Desktop.
Save annagapuz/0911d65f809a5147e63b0e579229ade2 to your computer and use it in GitHub Desktop.
CSharpSSEClient
namespace StreamingAPIClient
{
public static class Program
{
public static async Task Main(string[] args)
{
Console.WriteLine("Run sample client");
HttpClient client = new HttpClient();
client.Timeout = TimeSpan.FromSeconds(5);
while (true)
{
try
{
Console.WriteLine("Establishing connection with the server ...");
using (var streamReader =
new StreamReader(await client.GetStreamAsync("http://localhost:8080/stream")))
{
while (!streamReader.EndOfStream)
{
var message = await streamReader.ReadLineAsync();
Console.WriteLine(message);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment