1

I try to get a connection between an UWP-programm and a "normal" C# application.

UWP:

StreamSocket s = new StreamSocket();
await socket.ConnectAsync(new HostName("localhost"), "8003");
BinaryWriter bw = new BinaryWriter(socket.OutputStream.AsStreamForWrite());
String toSend = "Hello World!";
byte[] text = Encoding.UTF8.GetBytes(toSend);
byte[] number = BitConverter.getBytes(text.Length);
if(BitConverter.isLittleEndian) Array.Reverse(number);
bw.Write(number, 0, number.Length);
bw.Write(text, 0, text.Length);

"normal" C#, after the TcpListener etablished a new ClientThread:

//client was accepted by the server and is an instance of TcpClient
BinaryReader br = new BinaryReader(client.GetStream());
byte[] number = new byte[4];
br.Read(number, 0, number.Length);
if(BitConverter.isLittleEndian) Array.Reverse(number);
int size = BitConverter.ToInt32(number);
byte[] buffer = new byte[size];
br.Read(buffer, 0, buffer.Length);
String recieved = Encoding.UTF8.GetString(buffer);
Debug.WriteLine(recieved);

But the server doesn´t recieves anything. And the int size is 0. But if i run the UWP-code on a "normal" C# application, by replacing the s.OutputStream.AsStreamForWrite() with client.GetStream() and using a TcpClient instead of an StreamSocket the server recieves the text. What am I doing wrong?

Greets Marcel

LongBit
  • 21
  • 2
  • http://stackoverflow.com/questions/33259763/uwp-enable-local-network-loopback – Hans Passant Jun 16 '16 at 14:59
  • That´s not the reason. I can connect to the server, but I can´t send data to the server. – LongBit Jun 16 '16 at 15:27
  • Maybe. But hopefully it is obvious that this is not supposed to work. UWP apps run in a sandbox that defeats local loopback intentionally. You can't get your app certified when you rely on it. – Hans Passant Jun 16 '16 at 15:39

0 Answers0