I have a app(webview + xamarin) which support websocket server.
But when I use chrome to debug js, the server side is so slow. I simplify the code as follows:
Task.Run(async () => { var tcpListener = new TcpListener(IPAddress.Any, 50505); tcpListener.Start(); while (true) { var tcpClient = await tcpListener.AcceptTcpClientAsync(); NSRunLoop.Main.BeginInvokeOnMainThread(() => { var sw = new Stopwatch(); sw.Start(); var text = NSPasteboard.GeneralPasteboard.GetStringForType(NSPasteboard.NSStringType); sw.Stop(); Console.WriteLine("ElapsedMs: " + sw.ElapsedMilliseconds); }); } }).ConfigureAwait(false);
Then I create a test html file contains websocket client js code.
- From terminal, run TcpListenerTest app.
- Open chrome, maximum it( let TcpListenerTest app to background).
- In chrome, open a web page, and copy some words(abount 100 words).
- Wait about 5 minutes.
- In chrome, open the test html file.
- Wait about 10 seconds and turn to terminal to see the output.
In most case, ElapsedMs is about 10,000( 10 seconds).
Only the first time after restart computer, it will occur.