static void Main(string[] args) { string data; string text = string.Empty; PackageData package; IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 9050); Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); Console.Title = "IdleRQ Secondary"; socket.Bind(ipep); socket.Listen(10); Console.WriteLine("Waiting for client"); Socket client = socket.Accept(); IPEndPoint newClient = (IPEndPoint)client.RemoteEndPoint; Console.WriteLine("Connected with {0} at port {1}", newClient.Address, newClient.Port); NetworkStream ns = new NetworkStream(client); StreamReader sr = new StreamReader(ns); StreamWriter sw = new StreamWriter(ns); sw.WriteLine("Connected success"); sw.Flush(); while (true) { try { data = sr.ReadLine(); if (data != null) { data = Base64Decode(data); Console.WriteLine(data); data = FormatType(data); JPackage frame = JPackage.Deserialize(data); package = frame.Value.ToObject <PackageData>(); text += package.DATA; } } catch (IOException) { break; } sw.WriteLine("ACK"); sw.Flush(); } ns.Close(); sr.Close(); sw.Close(); Console.WriteLine(); Console.WriteLine("*********************** Text file ************************"); Console.WriteLine(); Console.WriteLine(text); Console.WriteLine("Disconnected"); }
public static string Serialize(JPackage message) { return(JToken.FromObject(message).ToString()); }