I'm trying to be the "enabler" of a TCP conversation between a handheld device and server app running on a PC by adding code to the handheld (C#, WindowsCE, CompactFramework). I ad[a,o]pted an example I found online to this:
TcpClient client = new TcpClient("PPP_PEER", 7727);
try
{
try
{
bool keepListening = true;
Stream s = client.GetStream();
StreamReader sr = new StreamReader(s);
StreamWriter sw = new StreamWriter(s) { AutoFlush = true };
while (keepListening)
{
sw.WriteLine("PING|");
int peekInt = sr.Peek()
ExceptionLoggingService.Instance.WriteLog(String.Format("Here is what was peeked at: {0}", peekInt));
String response = sr.ReadLine();
ExceptionLoggingService.Instance.WriteLog(String.Format("Here is the response: {0}", response));
if (!(response.Contains("DISCONNECT")))
{
keepListening = false;
}
}
s.Close();
}
finally
{
client.Close();
}
}
catch (Exception ex)
{
String msgInnerExAndStackTrace = String.Format(
"{0}; Inner Ex: {1}; Stack Trace: {2}", ex.Message, ex.InnerException,
ex.StackTrace);
ExceptionLoggingService.Instance.WriteLog(String.Format("From FileXferLegacy.SendDataContentsAsXML(): {0}", msgInnerExAndStackTrace));
}
The server does receive the "PING|" message and, in fact, it responds to it, according to its own display. It claims that it sends back "Responding to at 127.0.0.1:59964*: PING|ACKNOWLEDGED|--12/17/2014--9:42:15 AM"
But the code above, running on the handheld, hangs on the "String response = sr.ReadLine();" line.
Note: What is written to the log file is:
Here is what was peeked at: 80
(Since it hangs on the readline, the subsequent log file entry is not made).
I'm guessing the "80" here is a port number, but what this means as to how I should proceed, I have no clue.
A scream shot of the conversation that takes place with the legacy client and the existing server can be seen in Update 2 here:
http://stackoverflow.com/questions/27513186/why-am-i-getting-an-endless-until-warmbooted-loop-with-this-code[
^]
* port is assigned randomly, and differs each time it is run