Note that there are some explanatory texts on larger screens.

plurals
  1. POServer not receiving write() here and there
    primarykey
    data
    text
    <p>I have a hard time figuring out weather it's the servers fault, or a bug in my application somewhere. If I look in Wireshark it looks as if it's sending the data to the server; but how can I be sure it's received?</p> <p>In regards to the server's fault.. it probably isn't, as it's a Java app running in the browser (I Just make my own client for it) and I can execute the commands just fine through the browser all the time. It also works in my app, but after 2-3 commands to the server (still connected), it stops working - like something is blocking the actual sending.</p> <p>Hope for some guidance. Maybe the loop has something to do with it? If I restart the application, the commands work fine again, so it's after some time it stops working. Actually had this bug for over 5 years now; but just compiled the app again and it's still a problem :-)</p> <p>Thanks for reading.</p> <p>I should probably mention that inside the HandleIncomingMessages() function I have this thread running sending a keep-alive to the server (character "g").</p> <pre><code>// Create send-alive thread. Thread aliveThread = new Thread((ThreadStart)delegate { do { Connection.Send("g"); Thread.Sleep(100000); } while (true); }); aliveThread.Name = "Send-alive Thread"; aliveThread.Start(); aliveThread.IsBackground = true; </code></pre> <p>Here's some snippets of how it works.</p> <pre><code>client = new TcpClient(server, port); //client.NoDelay = true; // both has same result using (stream = client.GetStream()) using (reader = new StreamReader(stream, Encoding.ASCII)) { do { try { // Read the stream into the buffer. while ((readBuffer = reader.ReadLine()) != null) { ConnectionHelper.HandleIncomingMessage(readBuffer); } } catch (Exception E) { WriteLine("CreateConnection() Exception: " + E.Message); WriteLine("CreateConnection() Exception: StackTrace: " + E.StackTrace); // Exit on error. Environment.Exit(1); } } // do while (stream.DataAvailable); // Clean up. reader.Close(); stream.Close(); client.Close(); WriteLine("Disconnected."); } </code></pre> <p>HandleIncomingMessage() just parses the data and sends commands to the Send() function below.</p> <pre><code>internal static void Send(string message) { if (stream.CanWrite) { byte[] byteData = Encoding.ASCII.GetBytes(message + Environment.NewLine); Encoding enc = Encoding.ASCII; WriteLine("Send(): " + enc.GetString(byteData)); // Send &lt;message&gt; stream.Write(byteData, 0, byteData.Length); stream.Flush(); return; } WriteLine("Send(): Exception: Cannot write to stream!"); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload