Last active
May 15, 2024 14:10
-
-
Save annagapuz/0911d65f809a5147e63b0e579229ade2 to your computer and use it in GitHub Desktop.
CSharpSSEClient
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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