// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Generic; using System.IO; using System.Net.Sockets; using System.Xml.Serialization; namespace E { public class Program { public static void Print(List lst) { foreach(T o in lst) { Console.WriteLine(o); } } public static string Object2Xml(T o) { XmlSerializer ser = new XmlSerializer(typeof(T)); StringWriter sw = new StringWriter(); ser.Serialize(sw, o); return sw.ToString().Replace("\r\n", ""); } public static void Send(List lst, string host, int port) { TcpClient cli = new TcpClient(host, port); StreamWriter sw = new StreamWriter(cli.GetStream()); foreach(T o in lst) { sw.WriteLine(Object2Xml(o)); } sw.Close(); cli.Close(); } public static void Main(string[] args) { List lst = new List(); lst.Add(new Data { Iv=123, Sv="ABC" }); lst.Add(new Data { Iv=456, Sv="DEF" }); lst.Add(new Data { Iv=789, Sv="GHI" }); Print(lst); Send(lst, "localhost", 1234); } } }