SocketException: Connection refused using EasyNetQ ManagementClient - c#

I have RabbitMQ with management console installed on my machine. Web interface is working on
http://localhost:15672
When I try to access Rabbit via code, I'm getting an exception:
var mcGuest = new ManagementClient("http://localhost", "guest", "guest", 15672);
var vhost = mcGuest.GetVhost("/");
{"No connection could be made because the target machine actively
refused it [::1]:15672"}
(source code for Management Client at https://github.com/EasyNetQ/EasyNetQ.Management.Client)
I'm running Visual Studio as Administrator, getting following output when running netstat -anb:
Line 35: TCP 0.0.0.0:5672 0.0.0.0:0 LISTENING
Line 37: TCP 0.0.0.0:15672 0.0.0.0:0 LISTENING
Line 39: TCP 0.0.0.0:25672 0.0.0.0:0 LISTENING
Line 200: TCP 127.0.0.1:15672 127.0.0.1:18577 ESTABLISHED
Line 212: TCP 127.0.0.1:18577 127.0.0.1:15672 ESTABLISHED
Line 484: TCP [::]:5672 [::]:0 LISTENING
What could be the issue?

Apparently the issue is with IPv6. Could be related to my environment.
When running EasyNetQ api on Debug, IPv6 is used and I'm getting the error. When running on Release, IPv4 is used and sockets works.
The immediate solution is to use
new ManagementClient("http://127.0.0.1", "guest", "guest", 15672);
Though I still don't know why localhost and IPv6 wouldn't work. You can see IPv6 is used by the exception details - [::1] which stands for localhost IP in v6.

Related

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

Haunted by KillerService.exe while attempting to get C# server & client programs to communicate (from same machine)

I made client & server programs in C# based on this example code.
Server program:
TcpListener tcpListener = new TcpListener(8080);
tcpListener.Start();
First time I ran this, Windows Firewall popped up and asked me if it should be allowed network access.
Client program:
IPHostEntry ip = Dns.GetHostEntry(tbServer.Text);//"MyComputer-MSI"
string addr = ip.AddressList[0].ToString();
TcpClient clientSocket = new TcpClient(addr, 8080);
At the last line above, I got the message:
An unhandled exception of type 'System.Net.Sockets.SocketException'
occurred in System.dll
Additional information: No connection could be
made because the target machine actively refused it
I made sure both programs (Client.exe and Server.exe) were allowed by Windows Firewall. No other antivirus currently enabled (as far as I know).
Checked for conflicts with command netstat -a -b:
[KillerService.exe]
TCP 127.0.0.1:8080 MyComputer-MSI:0 LISTENING
The strange thing is that KillerService.exe (which I can't find in any of the tabs when I CTRL-ALT-DEL) changes its address to match whichever port I use for the server program.

C# : SMTP error

i am creating an email client that sends e-mail address from server ip instead of SMTP , i wrote the following code:
SmtpClient server = new SmtpClient();
server.Host= "50.23.128.66";
server.Port = 25;
server.Send("from#yahoo.com", "to#yahoo.com", "hi", "hope it works");
but when i run it, i get that error:
Unhandled Exception: System.Net.Mail.SmtpException: Service not
available, closing transmission channel. The server response was:
Cannot connect to SMTP server
50.23.128.66 (50.23.128.66:25), connect error 10061
i actually think that port is wrong . * By the way i am using Windows Server 2008 *
I think "connect error 10061" is the same as errno == ECONNREFUSED on a POSIX platform, which means the connection did not succeed, probably because the host you tried to connect to isn't running any sort of server on port 25.
According to this SMTP Server Test the server is not open to receiving connections on port 25:
No connection could be made because the target machine actively refused it 50.23.128.66:25
It's possible the server uses some form of encryption, and you will have to connect on one of the "secure" SMTP ports.
Are you sure it's an SMTP server, and not an IMAP server or the like?

chat.facebook.com connection time out error

I write the following code in my project.
TcpClient tcp = new TcpClient();
tcp.Connect("chat.facebook.com", 5222);
When I run my project,I got the following error.
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 69.171.227.26:5222
Anybody advice me?
Are you sure there's no firewall in place between you and chat.facebook.com which is blocking your outbound access on port 5222?
For example, I just did this:
$ telnet chat.facebook.com 5222
Trying 66.220.151.99...
Connected to chat.facebook.com.
Escape character is '^]'.
so it's fine for me

No connection could be made because the target machine actively refuses it

I'm working on a simple hello world TCP/IP client server app in C# and am unable to get my client to connect. Can anyone offer any additional troubleshooting steps? I'm starting to run out of ideas...
Here are the relevant sections of code:
server:
Console.Out.WriteLine("About to bind address");
IPAddress ipAd = IPAddress.Parse("127.0.0.1");
Console.Out.WriteLine("Choose a port to bind...");
String port = Console.In.ReadLine();
int iPort = Int32.Parse(port);
TcpListener myList = new TcpListener(ipAd, iPort);
myList.Start();
Console.WriteLine("The server is running at: "+myList.LocalEndpoint);
Console.WriteLine("Waiting for a connection.....");
Socket s = myList.AcceptSocket();
Console.WriteLine("Connection accepted from " + s.RemoteEndPoint);
client:
Console.Out.WriteLine("enter address: ");
string address = Console.In.ReadLine();
Console.Out.WriteLine("enter port: ");
int port = Convert.ToInt32(Console.In.ReadLine());
TcpClient tcpclnt = new TcpClient();
Console.WriteLine("Connecting.....");
Console.Out.WriteLine("Address: " + address + ":" + port);
tcpclnt.Connect(address, port);
I am able to ping the server from the client machine, however I am unable to telnet to the server using the bound port. I've tried a variety of ports (a few in the low 8000s and a few up around 40000). I have disable windows firewall on both systems. The systems are connected to a router which is not on the internet. I've tried with and without port forwarding set to forward incoming requests on the given port to the server machine with no effect.
The only exception that I've been able to trap is thrown by the client:
No connection could be made because
the target machine actively refuses
it.
I checked for an InnerException but it seems that there are none - that is the base exception. Could that be right?
Not sure what else I should be looking at - any additional troubleshooting steps would be helpful.
Thanks!
I've run into this before. The trick is to bind to 0.0.0.0 rather than 127.0.0.1. When you bind to 127.0.0.1 the server will only accept connections from localhost. Binding to 0.0.0.0 it will accept all requests.
You also may want to nmap the host machine from the client and see what ports it sees as being open.
EDIT: If you hard code the IP address of the machine in it the listener will only listen on that network interface. If you use 0.0.0.0 the listener will listen on all available network interfaces. This includes interfaces between your computer and a USB attached hand held device, a second network card or a VPN link.
The code above is listening to request coming from the loopback address. This will effectively only listen to connection on that network, and that network only includes your machine.
Have you tried listening to the address bound to the network from which the connection should be coming? On a local network it should be something like 192.168.x.x or 10.x.x.x
try netstat -al on your machine (the exact command line varies between Windows and unix) and see if the server is listening on the port
Why don't you use .NET remoting? It is better than doing a TCP/IP client server. You can pass messages between objects.
Have you tried running the client server on the same machine to make sure the connection is made first? Beyond that try using the router assigned or static IP of the machine running the server vs binding to loopback.

Categories

Resources