Trying to write a simple bit of code to connect to an IMAP server using StreamSocket. It reads the server connect response, but then it won't read anything else.
private async void TCPTest(string hostName, string port)
{
status.Text = "start of TCPTest";
StreamSocket socket = new StreamSocket();
await socket.ConnectAsync(new HostName(hostName), port);
string senddata = "A001 login uuu ppp";
status.Text += "\n first reading...";
DataReader reader = new DataReader(socket.InputStream);
reader.InputStreamOptions = InputStreamOptions.Partial;
await reader.LoadAsync(1024);
string data = reader.ReadString(reader.UnconsumedBufferLength);
status.Text += "\n > read " + data;
status.Text += "\n writing...";
writer = new DataWriter(socket.OutputStream);
writer.WriteString(senddata);
await writer.StoreAsync();
status.Text += "\n > wrote " + sendata;
status.Text += "\n second reading...";
writer = new DataWriter(socket.OutputStream);
await reader.LoadAsync(1024);
string data2 = reader.ReadString(reader.UnconsumedBufferLength);
status.Text += "\n >" + data2;
status.Text += "\n end of TCPTest";
}
This is the output I get.
start of TCPTest
first reading...
> read * OK mydomain.com IMAP4rev1 MDaemon 13.0.1 ready
writing...
> wrote A001 login uuu ppp
second reading...
The app never gets any further than this. There's no error, it just hangs. Am I doing something fundamentally wrong here? My code is the same (more or less) as the StreamSocket example on MSDN
Turns out I wasn't terminating my command. Adding
Environment.Newline
to the end solved things.