Question

I'm currently trying to port my app over from .NET to Windows Store, but I'm not able to get my UDP telnet communication to work.

I've enabled Internet (Client), Internet (Client and Server), and Private Networks in the App Manifest and I've tested other UDP communications and they have succeeded, but when I try to send telnet commands, it does not work.

The code in particular that I'm working on is a translation of the following C#:

var client = new TcpClient("192.168.1.152", 23);
var stream = client.GetStream();
try
{
    var encoder = new ASCIIEncoding();
    var outBuffer = new byte[_bufferSize];
    var buffer = encoder.GetBytes(command);

    await stream.WriteAsync(buffer, 0, buffer.Length);
    return true;
}
catch (IOException)
{
    return false;
}

and my Windows Store Compatible code looks like this:

var socket = new DatagramSocket();
var hostName = new HostName("192.168.1.152");
var stream = await _socket.GetOutputStreamAsync(_hostName, "23");

var writer = new DataWriter(stream);
writer.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf8;

try
{
    var buffer = Encoding.UTF8.GetBytes(command);
    writer.WriteBytes(buffer);
    await writer.StoreAsync();
    return true;
}
catch (IOException)
{
    return false;
}

The code runs and the method returns true (no exception), but when I run the code and monitor with WireShark, I notice that there is no new telnet traffic generated from the Store App code, and the receiving device does not process any commands sent. The .NET code, ran on the same machine, works flawlessly.

Also, if I try and subscribe to the socket.MessageReceived += MessageReceived when the event is fired I get the following exception when I try to call args.GetDataReader():

An existing connection was forcibly closed by the remote host. (Exception from HRESULT: 0x80072746)

What could be causing this data to not be sent from the Windows Store App? Is there any special restrictions on sending telnet data? Or is port 23 somehow being blocked from my app?

Was it helpful?

Solution

Use TCP

Why are you using UDP when the code you are translating from and Telnet use TCP? That would be why Wireshark does not pick it up as Telnet. As for the exception on MessageReceived we would have to see your code - did you bind your listening socket correctly?

;)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top