0
votes

I am trying to share some files from my raspberry pi running Windows 10 iot core. I am using StreamSocketListener as explained by Microsoft: https://docs.microsoft.com/en-us/windows/uwp/networking/sockets

My code is as follows:

private async void Testserver()
        {
            try
            {
                streamSocketListener = new StreamSocketListener();


                await streamSocketListener.BindServiceNameAsync("9000");
                streamSocketListener.ConnectionReceived += StreamSocketListener_ConnectionReceived;
            }
            catch
            {
                textb.Text = "server not started";
            }
        }

        private async void StreamSocketListener_ConnectionReceived(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args)
        {
            string response = "HELLO WORLD!";
            using (Stream outputStream = args.Socket.OutputStream.AsStreamForWrite())
            {
                using (var streamWriter = new StreamWriter(outputStream))
                {
                    await streamWriter.WriteLineAsync(response);
                    await streamWriter.FlushAsync();
                }
            }
        } 

Now when i try to hit 192.168.1.18:9000, it should at least trigger the ConnectionReceived event which it is not as I have added breakpoints there.

Could there be an easier way to send text files within a local network other than StreamSocketListner?

1

1 Answers

0
votes

For security reason, the port 9000 is not accessible by default. You need to use following command to add a rule for this port in firewall.

netsh advfirewall firewall add rule name="File Access" dir=in protocol=TCP localport=9000 remoteip=any action=Allow