Send List of Strings from Python to C# Using TCP/socket

Viewed 13

What is the preferred way to send a list of strings from a python server to a C# client using TCP/sockets?
I've come across tangentially related sources but so far, nothing that specifically addresses this issue (judging by my limited background in networking).

A simple example would be much appreciated!

Thanks!

1 Answers

Use JSON: ["string 1", "string 2", "string 3"] If your Python server can use an HTTP protocol (for which there are multiple implementations) you can simply use any of the HTTP clients built into .NET. Here's one example:

using System.Text.Json;

using var client = new HttpClient();
var content = await client.GetStringAsync("http://your.server/url");
Console.WriteLine(content);

var stringArray = JsonSerializer.Deserialize<string[]>(content);
Related