public void StartListening() { R = RowacCore.R; R.Log("[Listener] Starting TCP listener..."); TcpListener listener = new TcpListener(IPAddress.Any, 28165); listener.Start(); while (true) { try { var client = listener.AcceptSocket(); #if DEBUG R.Log("[Listener] Connection accepted."); #endif var childSocketThread = new Thread(() => { byte[] data = new byte[1048576]; // for screenshots and tasklists int size = 0; while (client.Available != 0) size += client.Receive(data, size, 256, SocketFlags.None); // TODO: increase reading rate from 256? client.Close(); string request = Encoding.ASCII.GetString(data, 0, size); #if DEBUG R.Log(string.Format("Received [{0}]: {1}", size, request)); #endif ParseRequest(request); }); childSocketThread.Start(); } catch (Exception ex) { R.LogEx("ListenerLoop", ex); } } }
internal static void Tests() { RLog rlog = new RLog("rlogTests", ""); try { RLog log = new RLog("[Test1]", ""); log.Log("test1"); Console.WriteLine("==="); log = new RLog("[><Test2.!?:|]", ""); log.Log("test2"); Console.WriteLine("==="); log = new RLog("[Test3]", ".\\NoSuchFolder"); log.Log("test3"); Console.WriteLine("==="); log = new RLog("[Test4]", ".\\NoSuchFolder\\Nonono"); log.Log("test4"); Console.WriteLine("==="); log = new RLog("[Test5]", ".\\NoSuchFolder\\No$uch4ol!?:der"); log.Log("test5"); Console.WriteLine("==="); rlog.Log("OK"); } catch (Exception ex) { rlog.Log("FAIL: " + ex.ToString()); } rlog.Log("END"); }
public void StartListening() { R = RowacCore.R; R.Log("[Listener] Starting TCP listener..."); TcpListener listener = new TcpListener(IPAddress.Any, 28165); listener.Start(); while (true) { try { var client = listener.AcceptSocket(); #if DEBUG R.Log("[Listener] Connection accepted."); #endif var childSocketThread = new Thread(() => { byte[] data = new byte[1048576]; // for screenshots and tasklists int size = 0; while (client.Available != 0) { size += client.Receive(data, size, 256, SocketFlags.None); // TODO: increase reading rate from 256? } client.Close(); string request = Encoding.ASCII.GetString(data, 0, size); #if DEBUG R.Log(string.Format("Received [{0}]: {1}", size, request)); #endif ParseRequest(request); }); childSocketThread.Start(); } catch (Exception ex) { R.LogEx("ListenerLoop", ex); } } }