C# server client fails on connect UWP (2) - c#

I am facing a problem to connect my Windows 10 PC to a Raspberry Pi running Windows 10 IoT (17763, which seems to be the most recent one) via TCP. The RPI shall be the server and the Windows 10 PC the client.
I found the following Socket documentation:
https://learn.microsoft.com/de-de/windows/uwp/networking/sockets
which provides a well understandable UWP example. That example runs the server and client in just one application. Reasoning:
To begin with as few moving parts as possible—and to sidestep network isolation issues for the present—create a new project, and put both the client and the server code below into the same project.
That examples runs fine either on PC or on RPI. I tried it by a) using “localhost” and b) the individual IP addresses of the PC and RPI => OK.
I split the example into two applications and run the server on RPI and the client on the PC. Of course, I added the IP address of the RPI in the client
static string Server = "192.168.178.78"; // Raspberry PI
...
var hostName = new Windows.Networking.HostName(Server);
Unfortunately, the connection is not established and the client times out (error 0x8007274C) .
In Wireshark (on PC) I can see:
No. Time Source Destination Protocol Length Info
320 34.221418 192.168.178.38 192.168.178.78 TCP 66 50198 → 1337 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 WS=256 SACK_PERM=1
plus a number of re-transmissions.
Since the connection does not work, I switched off the firewall on the PC. This doesn’t help either. Although port settings shouldn't matter, I opened TCP port 1337 on my router.
In the following thread, the same issue occurred, but this was due to running both applications on the same machine. Once Sven separated client and server to PC <-> mobile phone, it worked for him.
C# server client fails on connect UWP
I did a CheckNetIsolation.exe Debug session for Client and server. Both gave the following result (Remark: only one session listed here):
C:\WINDOWS\system32>CheckNetIsolation.exe Debug -p=S-1-15-2-1267940166-3928243817-861952377-2407264183-3106597897-3574865703-2117263357
Eine Netzwerkisolations-Debugsitzung wurde gestartet.
Reproduzieren Sie das Szenario, und drücken Sie dann STRG+C.
Protokolle werden gesammelt........
Zusammenfassungsbericht
Status der Netzwerkfunktionen
----------------------------------------------------------------------
InternetClient Not Used and Insecure
PrivateNetworkClientServer Not Used and Insecure
Detaillierter Datenverkehrsbericht
----------------------------------------------------------------------
InternetClient Not Used and Insecure
------------------------------------------------------------------
PrivateNetworkClientServer Not Used and Insecure
------------------------------------------------------------------
OK
Any idea? I would highly appreciate proposals to fix that issue.

Refer to Michael Xus comment. The port on the Raspberry Pi had to be opened by
netsh advfirewall firewall add rule name="pidart port 1337" dir=in action=allow protocol=TCP localport=1337
This solved the issue

Related

ASP.NET Core disable HTTPS

I have a dockerized ASP.NET Core app that I'm trying to run locally under Linux (Fedora 33). I'd like to disable HTTPS so I don't have to deal with constant certificate errors.
To do this I simply disabled the HTTPS redirect feature which is included by default, however the app then wasn't responding to any HTTP requests at all.
I managed to get the dev version of the app to run on HTTP by explicitly configuring Kestrel in Startup.cs:
webBuilder.UseKestrel(options => {
options.ListenAnyIP(5000);
});
However, it isn't working for the Production version of the app. Whenever I send a request to http://0.0.0.0:5000, I just get a curl: (56) Recv failure: Connection reset by peer error.
Running netstat -ap in the container doesn't show the app as being bound to the port:
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 localhost:46825 0.0.0.0:* LISTEN -
udp 0 0 localhost:36022 0.0.0.0:* -
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node PID/Program name Path
unix 2 [ ACC ] STREAM LISTENING 27739639 1/dotnet /tmp/dotnet-diagnostic-1-3889474-socket
During startup the app also doesn't display the same information that I would normally expect, e.g. the following from another of my dockerized ASP.NET Core apps that does use HTTPS:
web-prod_1 | Hosting environment: Production
web-prod_1 | Content root path: /app
web-prod_1 | Now listening on: https://[::]:443
web-prod_1 | Now listening on: http://[::]:80
web-prod_1 | Application started. Press Ctrl+C to shut down.
The app doesn't print any of this on start, which is a little concerning.
I'd really appreciate any help with this, I've tried just about everything I can think of and I'm pulling my hair out over it.
EDIT
The cause of this was unrelated to HTTPS - a HostedService with a StartAsync that didn't terminate was being added in Startup.cs. Somehow this was stopping the rest of the app from starting, but only in production builds. Moving the AddHostedService call to Program.cs resolved the issue.
But is the container engine actually starting with the flags to bind the container and hosts ports? Conection reset means that the port is closed and actively rejecting connection.
You mention you did a netstat from inside the container, can you run another one from the host while the container is running? I like to use netstat -plnt
If your container is exposing the correct ports to the OS you should see it and be able to reach it at localhost:port, here I have a mysql proxy exposing 3306
❯ sudo netstat -plnt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
1/init
tcp6 0 0 :::3306 :::* LISTEN 300988/containers-r
Which I had to specify the port binding when launching it (depending on your container engine this is done in different flags/options)
docker run -ti -p 3306:3306 eu.gcr.io/xxx-xx/svc-xx-xx-tests
1st cheek by other browser
or
cheek blocking antivirus or firewall of your PC may interrupted it.
then
change the port number before by cheeking the ip and port number by ip scanner.
as you now when you need change http to https need SSL certificate , so set disable option Tools->option->environment->webbrowsers

Cannot get Mosquitto to Allow Connection from Outside Local Network

I have Linux Ubuntu 18.04 laptop, and I installed the Mosquitto MQTT broker there. On my Windows 10 laptop, I am running a C# application written in Visual Studio 2013 that uses the M2Mqtt Libraries.
If I connect via the localhost, everything is fine. I start up the Mosquitto server, connect via the C# application, subscribe to a topic, and then can send messages back and forth all day long.
But when I try to connect through the internet address, I consistently get a uPLibrary.Networking.M2Mqtt.Exceptions.MqttConnectionException:
"No connection could be made because the target machine actively
refused it 95.XXX.XXX.134:1883" error. (The address there is what I got via "WhatsmyIP")
Here's what I have done so far:
First, I went to my router, which is a TP-LINK AC1200. I set the port to forward to the local IP address of the Linux box.
Then I went to my Linux box and used ufw to enable port 1833 and enable the firewall
From there I have tried everything I can think of -- I've run Mosquitto with the port declared at the command line, I have changed the conf file to say:
Listener 1883 0.0.0.0
and
Listener 1883 192.168.0.144
I have removed the port assignment and listener assignment entirely (since that is its default anyway) and always I get the same result.
I downloaded 2 different utilities -- one on an android phone and one is an app available from Windows store, and I cannot connect with either of them, either. The Android phone simply will not connect (it is not on the same network so localhost is not an option) and the other app will connect locally, but not when I change to the internet address.
I get the sense I'm just missing one small thing, but I can't figure out what it is. There are other stackoverflow questions that show the same error, but they don't help me.
If it matters, the actual C# code that is being run is:
try
{
System.Security.Cryptography.X509Certificates.X509Certificate caCert = null;
Boolean useSecureProtocol = false;
int OpenPort = 1883;
// external IP address
String PublicIPAddress = "95.XXX.XXX.134";
// local IP address
String LocalIPAddress = "192.168.0.144";
System.Net.IPAddress ipaddress = System.Net.IPAddress.Parse(PublicIPAddress);
client = new MqttClient(ipaddress, OpenPort, useSecureProtocol, caCert, MqttSslProtocols.TLSv1_0);
// certificate and Protocol are irrelevant because security set to false??
}
catch (System.Net.Sockets.SocketException SException )
{
string SEX = SException.Message;
}
* * *
try
{
Byte retVal = client.Connect(ClientId);
}
catch (uPLibrary.Networking.M2Mqtt.Exceptions.MqttConnectionException ex)
{
string m = ex.Message;
}
Config File: conf.d (which I run explicitly with the -C option)
# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example
#
pid_file /var/run/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /home/mark_admin/mosquitto.log
include_dir /etc/mosquitto/conf.d
As I said, I have changed it and tried many things:
Listener 1883 192.168.0.144
Listener 1883 0.0.0.0
Listener 1883
And none of the above. Just left it blank. None of them worked.
I'm posting this as an answer so I can give more detail in case anyone stumbles upon this in the future.
Setting up the MOSQUITTO MQTT Server in Ubuntu 18.04 is actually not hard, but the steps are important.
Step 1: Install Mosquitto Software
sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
sudo apt-get update
sudo apt-get install mosquitto
Step 2: Open Port 1883 and start firewall
sudo ufw allow 1883
sudo ufw enable
Step 3: Verify Mosquitto is not already running
pgrep mosquitto
[Note, if any number shows, that is the PID of an already running Mosquitto. You can just kill it. Also, you can try: sudo service mosquitto stop]
Step 4: Start Mosquitto with verbose option
mosquitto -v
[Note: This starts Mosquitto without using any config file. It echos connection and status information to the screen. Easiest for quick debugging.]
Step 5: Check connectivity using local host
Go to your client machine (in my case a Windows 10 laptop) and run the MQTT client, connecting to the local address of the Linux Mosquitto server (in my case 192.168.0.144). You should be able to connect. In fact, you can do this step before you even open the firewall, since this is all on the local network, the firewall rules are irrelevant at this point. Until next step which is...
Step 6: Check Connectivity using web tool
use either: www.yougetsignal.com/tools/open-ports/ or
https://canyouseeme.org/
[NOTE: You will not get an OPEN state UNLESS THE MOSQUITTO BROKER IS RUNNING]
Step 7: If Port Shows Closed When coming In from Internet (ie not localhost)
Here's where I got tripped up. In my case, I have a Verizon Modem that ALSO has a firewall (because it has a router). I have my own wireless router, a tp-link Archer C1200, that I have plugged into the Fios Modem/Router. I started by putting the port forwarding in the tp-link. But that firewall comes after the Fios firewall so I needed to go to the first wall and do the port forward there.
And this is the second thing that is tricky. All of the online how-to's said I should forward port 1883 to the local IP address of my Linux Server, which in my case was 192.168.0.144. But that was not correct in my case. The Archer C1200 was actually the device that I needed to forward to -- it handled the correct distribution from there. It had an address of 192.168.0.152 assigned to it from the Verizon router. I still have both forwardings in place (ie the Fios and the tp-link) and my guess is that I need them both.
Now all pathways are open, you can follow the other Mosquitto instructions regarding logging, config files, Daemons, etc.
Hope this saves someone some time down the road!

Reverse SSH Tunnel or TCP tunnel using the Remote Desktop Services API

I'm making an application that will allow for bidirectional desktop control for my own learning process, I don't like when standard RDP sessions lock the endpoints computer when a RDP session is in progress.
The setup is as follows:
SSH Server at home
Computer A at home.
Computer B at client endpoint.
The problem is that I cannot establish a connection with the connection string provided through the RDP API. I have attempted NAT UPNP port forwarding but I have ruled this out as a solution.
My current avenue of interest is to create a reverse ssh tunnel, and to have machine B tunnel into the ssh server, from that point Computer A will run:
ssh -l 3389:127.0.0.1:3389 credentials <-- Currently I'm doing this through putty. (Will use a ssh library to do this automatically)
Secondly it might also be possible to establish a connection via TCP:
Client B -> connects to Client A (Or the server links them and routes data)
Client B Generates RDP string
Client B Sends RDP string to client A
Client A attempts to connect to client Bs active RDP session.
..Here I hit a wall. Since the connection string generated points to one publicly routable address (IPv6) and the rest are temp IPv6 Addresses and the private IPv4 Address and the Link-Local address.
Computer B will then reverse tunnel into the ssh server:
ssh -R 6000:127.0.0.1:3389 credentials <-- Also through putty for testing.
This works if I were to open the built in remote desktop application and target
localhost:6000
but I want the client (computer B) to generate a connection string and send it via TCP (I can handle this internally, but have been just copy pasting the connection string manually. Still just for testing.)
Here is the connection string broken down into its tags:
<E>
<A KH="QHltZY9ISIdaMb3DNLVCVL8z22Q="
KH2="sha256:cEv4C57cmofFr8bJsttCX+taX5sWxWmgvSjpWRpTZ8U="
CE=
"MIIC4jCCAcqgAwIBAgIQSbu3zINwkqBB78x2uwORijANBgkqhkiG9w0BAQsFADAa
MRgwFgYDVQQDEw9QcmltYXJ5LURlc2t0b3AwHhcNMTgwNjA4MDY1MDU1WhcNMTgx
MjA4MDY1MDU1WjAaMRgwFgYDVQQDEw9QcmltYXJ5LURlc2t0b3AwggEiMA0GCSqG
SIb3DQEBAQUAA4IBDwAwggEKAoIBAQDQ4tSRTPnCJuhCEJoOY8veHaFNg02Zmlg+
3eXZCH65Rejxlk1cmARknhw5+MuXTvka+oApQeWtZQBTpoE/KD1vaHOnQS0yLc8P
g6BvekNcoOY+6U9zOc1dP+EignJ8dHkSYc8Jr+k/OCfDTFoQZ/HVRUKHwd1ScNa2
YczGSrhboCevbSQxSTtcsI7H4tL6d58fdlp+lPXkLCkzo29IQCqKT5q94geXLvDa
t/U2rK6OcRFycEoNrwNPy7bwAnfIRTFDrLiQ8/6b28DrpPM7cJyM+K6cqsIOkkAd
gXPJNNMMKT3ej1KDTZ+UiLq3c9plPP7SUm9xLx7rhEct+zTf8RUhAgMBAAGjJDAi
MBMGA1UdJQQMMAoGCCsGAQUFBwMBMAsGA1UdDwQEAwIEMDANBgkqhkiG9w0BAQsF
AAOCAQEApU2ec3ZgWDHQ4/gsXv/wlpLeIMbeIpZrf9NpgqV6Ig3SR8PMldEgfGfz
XpB6C8mdoqCQglVWijr7M/QvZ9emrwNkfEDiKFuUHUETvdSD48jPJEwGtphhM58e
07O+y8VP5vrOn0uR/VTKx8M9OMBehDhu9SC1H3/NGqRfbGDleCbTz1KvAFKOJrCH
EvDHB+hyUFlapW/q/ZIMOefaYFYv/vnZvI6Sfy/NDKkSaOR0RBjrRA2dbmj6D0YU
EuU1FYwqmTtW8jlmoz2WfaLEli8QLkGx6lw1ej891g5AvvdD1UWVAUfssIlMl1YL
NSp6g8qJJrKtQvlCVUxwG4IH4ufb9w=="
ID="secretusername"
/>
<C>
<T ID="1" SID="0">
<L P="55114" N="fe80::710b:8671:823c:7aab%17"/>
<L P="55115" N="2604:282:3900:8eb0::af33"/>
<L P="55117"N="2604:282:3900:8eb0:710b:8779:28c3:7aab"/>
<L P="55117" N="2604:282:3900:8eb0:5dc5:b08e:de21:8bb8"/>
<L P="55118" N="10.0.0.14"/>
</T>
</C>
</E>
It may be important to note that many of the addresses listed between the < T > tag are redundant
My question is mainly: Is there a way that I can generate a connection string that will support reverse ssh or allow TCP to reroute data and provide an address that is publicly accessible, or is there a way I could append my own tag to the connection string: that would allow the connection to work.
The application works on local networks without error. I have searched for answers on the specific question that I am trying to solve any advice is appreciated, thank you.
TLDR
Machine A:
ssh -L 3389:127.0.0.1:3389 credentials
Machine B:
ssh -R 6000:127.0.0.1:3389 credentials
SSHD:
Connects the two tunnels
Machine A: Built in windows utility can target localhost:6000 and remotely connect to machine B.
Problems: don't want to use built in utility.
Cannot connect remotely using the connection string generated by machine B. As it only points to the local address of the device.
So, how can I generate a connection string that supports a publicly routable address, without having the port forward.

Running SignalR server on VM and consuming by Xamarin

My goal: I want to run SignalR server app (ASP.NET website hosting SignalR) and consume it by Xamarin app. Basically the server (website) must be accessible outside my local machine.. and here's my first problem.
My env configuration: I have a MacOSX and VMWare installed on it with fresh Windows 10 and VS2017. I just built a simplest possible SignalR web chat application. When I'm running it from VS, Google Chrome opens the browser with address: localhost:49919 and It works:
The problem: Before I even start to consume it by mobile emulators I must be sure that this website is accessible a least in local network. So I typed in browser (in Windows VM): 10.0.1.58:49919 and it didn't work. 10.0.1.58 - this is my vm IP (network configuration is bridged). Same result when I opened this address on my Mac:
My effort:
I set vmware Network setting to "Bridged Networking" -> "Wi-fi" and got IP=10.0.1.58 (there is also an option of Autodetect)
I typed ipconfig and ifconfig on both machines:
Windows10 (vm):
Ethernet adapter Local Area Connection:
IPv4 Address. . . . . . . . . . . : 10.0.1.58
On Mac (I'm not sure where to look), but I have:
lo0:
...
inet 127.0.0.1 netmask 0xff000000
...
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
en0:
...
inet 10.0.1.54 netmask 0xffffff00 broadcast 10.0.1.255
...
media: autoselect
status: active
en1:
...
media: autoselect <full-duplex>
status: inactive
en2:
...
media: autoselect <full-duplex>
status: inactive
bridge0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=63<RXCSUM,TXCSUM,TSO4,TSO6>
ether 4a:00:07:58:56:b0
Configuration:
id 0:0:0:0:0:0 priority 0 hellotime 0 fwddelay 0
maxage 0 holdcnt 0 proto stp maxaddr 100 timeout 1200
root id 0:0:0:0:0:0 priority 0 ifcost 0 port 0
ipfilter disabled flags 0x2
member: en1 flags=3<LEARNING,DISCOVER>
ifmaxaddr 0 port 5 priority 0 path cost 0
member: en2 flags=3<LEARNING,DISCOVER>
ifmaxaddr 0 port 6 priority 0 path cost 0
nd6 options=201<PERFORMNUD,DAD>
media: <unknown type>
status: inactive
p2p0:
...
media: autoselect
status: inactive
awdl0:
...
media: autoselect
status: active
utun0:
...
inet6 fe80::c3a4:bc19:f3f9:a5e7%utun0 prefixlen 64 scopeid 0xa
...
vmnet1:
...
inet 192.168.89.1 netmask 0xffffff00 broadcast 192.168.89.255
vmnet8:
...
inet 192.168.42.1 netmask 0xffffff00 broadcast 192.168.42.255
I turned off firewall and keep it disabled for entire time
I complie and run the project: I see "http://localhost:49919/Default.aspx" in the browser - it works!
I open new tab with this address: "http://10.0.1.58:49919/Default.aspx", and I have (same on windows and on mac) this error:
I tried the same with a totally wrong IP (there is no ping for 10.0.1.99) just to see if the results are the same, so: "http://10.0.1.99:49919/Default.aspx". This result:
So.. it doesn't work, and I meet all Dennis1679 conditions (in his first answer).. I think.. But...I've done two more things:
In this file: .vs\config\applicationhost.config of my VS solution, I changed the "localhost" to real ip "10.0.1.58".
So change this line:
<binding>binding protocol="http" bindingInformation="*:49919:localhost</binding>
into this line:
<binding>binding protocol="http" bindingInformation="*:49919:10.0.1.58"</binding>
then... I resterted IIS (in cmd line iisreset command), restered VS, run the project and... didn't work. Same result - "Invalid Hostname". So still localhost:49919/Default.aspx works, but 10.0.1.58:49919/Default.aspx does NOT :/
Last step(s).. I removed .vs folder so I know sln config is clean, restarted VS and:
Run Power Shell as admin
run this command: netsh http add urlacl url=http://10.0.1.58:49919/ user=everyone
"URL reservation successfully added"
restert IIS (in cmd line iisreset command)
change the "localhost" to real ip "10.0.1.58" in this file .vs\config\applicationhost.config
AND... the result is a little bit different, so that's interesting:
So something happened... But I can't go anywhere from there...
You just installed new windows10, vs2017 and created empty website with singnalR server.. What do you do access this website/chat from Mac?
Two things I can conclude from your post.
Your IIS Express server is running.
Meaning that you can access your website from your Windows 10 machine.
One (or both operating) system(s) operate on the 10.0.1.xx subnet. It says so in the error message.
You say you are running VMware.
Now a couple things can be causing the problem to communicate between devices.
Your Network Device settings in VMware of the guest machine(windows 10) is not set to bridged mode. Meaning your Windows might be on the IP range of 10.0.1.xx and your host machine(MAC) on the 192.168.1.xx network.
Conclusion Only if you select bridged network mode for the VMware network settings of the guest machine, only then will you be on the same subnet automatically.
The question is:
What do you do access this website/chat from Mac?
1 . Make sure the VMware network card of the Guest machine(WIN10) is in bridged mode.
[On Windows] pressing WINkey+R type cmd and type ipconfig. Check what your, depending on how you connect to your internet, IPv4 Address is for your Wireless or Ethernet card.
[On MAC] open up the terminal, eg. by pressing cmd+space and typing terminal.
Then type ifconfig and hit enter.
If those are the same, next step.
Add binding lines to .vs\config\applicationhost.config
In the applicationhost.config file you have a line that says
<binding>binding protocol="http" bindingInformation="*:49919:localhost</binding>
Add a new line below this one current <binding></binding> with your guest machine's IP address.
Eg. <binding>binding protocol="http" bindingInformation="*:49919:192.168.0.12</binding>
Now save the file and continue to the next step.
You open a port in the Windows firewall (or turn it off, but I recommend against it.)
Open the port on your guest machine (Control Panel > System and Security > Firewall > Advanced settings and add Inbound rule)
Done that? Step 4.
On your Mac go to your browser. Go to 10.0.1.xxx:port.
Right now, if you followed all the steps correctly, you should be able to see the website.
If at this point it still isn't working and you need more help, please edit your question to explain what is happening. Or head on over to networkengineering.stackexchange.com, they are there for network problems.

Telnet to the RabbitMQ Stomp adapter just hung

I am using RabbitMQ server 3.5.6 on windows 8.1 and Windows 7 x64.
I have to access the Stomp Adapter embedded with the RabbitMQ Server.
So i have configured it from https://www.rabbitmq.com/stomp.html
it shows that it is successfully enabled and configured the rabbitmq_stomp.
After doing this i have restarted my computer and try to telnet to the localhost 61613 (the default socket of the rabbitmq_stomp) and it just hung in there saying connecting.
The RabbitMQ server log says:
=INFO REPORT==== 4-Dec-2015::17:53:29 ===
accepting STOMP connection <0.327.0> ([::1]:49397 -> [::1]:61613)
what did i do wrong? any help would be appreciated.
I find out a way to test the STOMP with RabbitMQ, you can issue the following command to test it. The solution here is by using nc, I didn't find a way using telnet under Windows though.
echo -e 'CONNECT\naccept-version:1.0,1.1,1.2\n\n\0' | nc -q10 127.0.0.1 61613
Normally the client should send the first byte in that protocal, usually something like CONNECT\naccept-version:1.0,1.1,1.2\nhost:yourstomp, needs a null byte , in this case is Ctrl-#, at the end to terminate, so that would be easier to send via echo -e or similar.

Categories

Resources