Telnet to the RabbitMQ Stomp adapter just hung - c#

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.

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

C# server client fails on connect UWP (2)

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

How do I connect to a Cassandra VM

The following code works if Cassandra and the code are on the same machine:
using System;
using Cassandra;
namespace CassandraInsertTest
{
class Program
{
static void Main(string[] args)
{
var cluster = Cluster.Builder()
.AddContactPoint("127.0.0.1")
.Build();
var session = cluster.Connect("test_keyspace");
session.Execute("INSERT INTO test_table (id, col1, col2) VALUES (1, 'data1', 'data2')");
Console.WriteLine($"Finished");
Console.ReadKey();
}
}
}
Assuming a username and password is needed if the code is on one machine and cassandra is on a different machine (different ip address)? So I have tried:
var cluster = Cluster.Builder()
.AddContactPoint("192.168.0.18") <- the ip address for the cassandra node
.WithPort(9042)
.WithCredentials("username to log into the cassandra node","password to log into the cassandra node")
.Build();
I get the following error message:
userone#desktop:~/Desktop/vsc$ dotnet run
Unhandled exception. Cassandra.NoHostAvailableException: All hosts tried for query failed (tried 192.168.0.18:9042: SocketException 'Connection refused')
at Cassandra.Connections.ControlConnection.Connect(Boolean isInitializing)
at Cassandra.Connections.ControlConnection.InitAsync()
at Cassandra.Tasks.TaskHelper.WaitToCompleteAsync(Task task, Int32 timeout)
at Cassandra.Cluster.Cassandra.SessionManagement.IInternalCluster.OnInitializeAsync()
at Cassandra.ClusterLifecycleManager.InitializeAsync()
at Cassandra.Cluster.Cassandra.SessionManagement.IInternalCluster.ConnectAsync[TSession](ISessionFactory`1 sessionFactory, String keyspace)
at Cassandra.Cluster.ConnectAsync(String keyspace)
at Cassandra.Tasks.TaskHelper.WaitToComplete(Task task, Int32 timeout)
at Cassandra.Tasks.TaskHelper.WaitToComplete[T](Task`1 task, Int32 timeout)
at Cassandra.Cluster.Connect(String keyspace)
at HelloWorld.Program.Main(String[] args) in /home/userone/Desktop/vsc/Program.cs:line 17
userone#desktop:~/Desktop/vsc$
The iptables on the node (the cassandra server) is currently set as follows:
node1#node1:~$ sudo iptables -S
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
-A INPUT -i lo -j ACCEPT
-A IMPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -s 192.168.0.73/32 -p tcp -m multiport --dports 7000,7001,7199,9042,9160,9142 -m state --state NEW,ESTABLISHED -j ACCEPT
node1#node1:~$
Note 1: Both the machine with the app and the machine with cassandra installed can be pinged and tracerouted in both directions.
Note 2: I have tested the username and password and can log into the cassandra server without any issues when tried directly on the server.
Note 3: Cassandra is running in a VM which I just created today. The VM is a guest machine on the host machine which runs the code.
Note 4: Both the Host OS and Guest OS are Linux.
.AddContactPoint("127.0.0.1")
If that works from the same machine, then you probably have Cassandra bound to that IP. If you need to connect to your node(s) remotely, then you need to bind a routeable IP to that node.
Run a nodetool status. If you see your cluster status showing your node with an IP of 127.0.0.1, then connecting to the local machine from the local machine is the only scenario that will ever work.
Try running the following command on your node:
grep _address cassandra.yaml
The IP address returned in the output is the only one that an application is allowed to connect to. If you want to be able to connect to 192.168.0.18, then the listen and rpc addresses should look something like this:
listen_address: 192.168.0.18
rpc_address: 192.168.0.18
Note that you'll need to change your seeds list, too.
Also, if you're on a VM/provider that has both internal and external IP addresses, then you'll also need to set your broadcast_ addresses to the external IP:
broadcast_address: 10.6.5.5
broadcast_rpc_address: 10.6.5.5
listen_address: 192.168.0.18
rpc_address: 192.168.0.18
But try setting just listen and rpc to 192.168.0.18 first.
Edit 20191022
Just wanted to double check, do I add 192.168.0.18 as the listen_address and rpc_address to the cassandra node where the cassandra node has the ip address 192.168.0.18?
Yes. Also make sure that your node's seed list is set like this:
- seeds: "192.168.0.18"
Before I did that, the value of the listen_address and rpc_address were set to localhost
I thought so.
However, after making the changes you suggested, nodetool status now gives me
Failed to connect to 127.0.0.1:7199 - connection refused
Ironically, that's the same message nodetool returns when Cassandra is not running. At this point I would check the system log and see if it is returning errors that may be preventing it from starting. I suspect that the seed list still reads "127.0.0.1".
tl;dr;
If you intend to connect to your cluster/node remotely, then you cannot use the default configurations which bind Cassandra to the home IP (127.0.0.1/localhost). And that includes all _address settings, as well as your seeds list.
I suggest using something like telnet 192.168.0.18 9042 to test whether the network is properly configured for this scenario. The error that the driver is throwing is just a standard socket error that is returned when the driver can't connect to the cassandra host.
I do not have any experience with Cassandra, but almost all of my connectivity problems were related to firewalls' configuration, OS distributed and network services, etc.
So, if everything works well locally, do not change anything in source code before you are entirely sure about it.
I suggest to check the following list first:
Check all servers' firewall configuration
Check if all needed services are run in all servers (search if Cassandra is depended on any services).
Check the network firewall and subnet port and protocol access limitation if exist.
Check if Cassandra is fully and functionally up and works on port 9042.

System process holding WCF TCP port after application using it is closed

I'm developing a C# .NET Framework based Web Service Library which is running over port 8733. Now I want to quickly create a console application that can start an instance of ServiceHost and host the Service so I don't need to have VS open and debugging it to have the Web Service running.
Here is my dirty console application code:
static void Main()
{
var host = new ServiceHost(typeof(WebService));
var bindig = new BasicHttpsBinding();
host.AddServiceEndpoint(typeof(IWebService), binding, new Uri("https://192.168.0.154:8733"));
host.Open();
Console.ReadLine();
}
But this throws an Exception when it hits host.Open()
System.ServiceModel.AddressAlreadyInUseException: 'HTTP could not register URL https://+:8733/. Another application has already registered this URL with HTTP.SYS.'
Inner Exception
HttpListenerException: Failed to listen on prefix 'https://+:8733/' because it conflicts with an existing registration on the machine.
So I thought "Oh I just forgot to stop the instance running from Visual Studio", but nope, that was stopped.
So I decided to investigate using netstat in a PowerShell window ran as Administrator. Executing netstat -a -o -n -b and piping it into a findstr "8733" I get the result
TCP 0.0.0.0:8733 0.0.0.0:0 LISTENING 4
TCP [::]:8733 [::]:0 LISTENING 4
Now using Task Manager I go and search for the process with the PID 4, lo and behold:
Now I have no idea why the System process is holding on to TCP Port 8733, and this even persists after a reboot. My question now is this; How can I manually bind to this Port?
P.S: Bonus points for answers that answer why the System process is holding the port and how the Web Service can bind to it when run from Visual Studio
Try to use an administrator account to run the service or use the below command to reserve the URL for the specific user so that it could occupy the system port arbitrarily.
Netsh http add urlacl url=https://+:8001/MyUri user=DOMAIN\user
Official document.
https://learn.microsoft.com/en-us/windows/win32/http/add-urlacl
The system continues to occupy a port, possibly because our website in IIS is bound to some port.
Feel free to let me know if there is anything I can help with.

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!

Categories

Resources