I'm trying to connect with my FTP server through StreamSockets but for some reason it keeps crashing and giving me this error while reading:
WinRT information: An established connection was aborted by the software in your host machine.
I'm using two streamsockets, one to connect with port 21 and the other one for the passive mode. And the passive mode read method is always crashing.
This is how I retrieve data:
async public Task RetreiveData()
{
try
{
if (rdr == null)
{
rdr = new DataReader(dataSocket.InputStream);
rdr.InputStreamOptions = InputStreamOptions.Partial;
}
await rdr.LoadAsync(1024);
if (rdr.UnconsumedBufferLength > 0)
{
Debug.WriteLine("Data response");
response += rdr.ReadString(rdr.UnconsumedBufferLength);
Notify = true;
}
else
{
Done = true;
OnReceivedMessageChanged(response);
}
}
catch (Exception ex)
{
throw;
}
}
and looping it in an backgroundworker like so
async void dataworker_DoWork(object sender, DoWorkEventArgs e)
{
while (true)
{
await RetreiveData();
}
}
And this is how I create my socket
StreamSocket dataSocket = new StreamSocket();
StreamSocketControl controller = dataSocket.Control;
controller.KeepAlive = true;
await dataSocket.ConnectAsync(new HostName(_server), port.ToString());
The funny is my port 21 streamsocket returns 226 statuscode from the server after my passive streamsocket crashes.
I'm breaking my head over this one.