Apache Thrift remote service timeout - c#

I set up Thrift to build two entities and a corresponding service. I genereated the code for C#, created a small console application for the server and another one for a test client. I ran both on my local machine and it worked like a charm. But when deploying the server on my Azure VM running Windows Server 2012, with an endpoint created on port 9090 for TCP, my client can't connect. There's a timeout.
Similar questions on SO: This one is about a php library specific problem and this one is about two linux machines. The latter one is close to my question, but I can imagine my problem is Windows or Azure VM specific.
I'm using Thrift 0.9.0.0 from NuGet. I tried SimpleServer and ThreadPoolServer. This is what I'm doing on the server:
Thrift.Server.TServer server = new Thrift.Server.TThreadPoolServer(new TodoThriftService.Processor(new TodoThriftServiceHandler()), new TServerSocket(9090));
This is what I'm doing on the client:
TodoThriftService.Client client = new TodoThriftService.Client(new TBinaryProtocol(new TSocket("my.host.com", 9090)));
I also tried the server IP address instead of its host name, but it didn't work either.
netstat -an output is:
TCP 0.0.0.0:9090 0.0.0.0:0 LISTENING
Output from telnet from client (telnet my.host.com 9090):
Verbindungsaufbau zu my.host.com...Es konnte keine Verbindung mit dem Host hergestellt werden, auf Port 9090: Verbindungsfehler
Which is German for "connection error".
When I visit http://canyouseeme.org/ on the server and check port 9090 the output is:
Error: I could not see your service on 123.34.567.890 on port (9090). Reason: Connection timed out
When I sniff packets with Wireshark on the server the output is:
1 0.000000000 12.3.456.78 12.34.567.89 TCP 66 53566 > websm [SYN] Seq=0 Win=8192 Len=0 MSS=1452 WS=256 SACK_PERM=1
And two retransmissions.
Note: The destination IP shown in Wireshark differs from the IP that canyouseeme.org determined.
Also note: Both connection attempts from my test client as well as from canyouseeme.org are shown in Wireshark.
Is my server console application doing anything wrong? It works fine on my local machine.

Because netstat reports that your server is listening on 9090, and because tcpdump reports that SYN packets are arriving to 9090, something else must be blocking the client.
My suspicion in this case would be some sort of local firewall (because the packets did arrive, but the OS should have answered with a SYN packet and you didn't see that). Check Windows Firewall to make sure port 9090 is open.

Related

SSH Access using Renci.SSH to MySQL Server

Trying to access a MySQL server using the Renci host SSH library.
I got it working by following the info Creating a forwarded port within an SSH tunnel
Specifically this line got my local port sucessfully set up such that it could be bound:
ForwardedPortLocal port = new ForwardedPortLocal("localhost", 3306, "localhost", 3306));
This is fine, but as I understand it the SSH client is binding to 3306 to receive data back from the server. This is a problem if the user has MySQL already installed as it will be using this port so my service cannot. Of course the service can be stopped but this is not a very friendly process.
I was expecting to be able to pass a High - Ephemeral - Port to listen on for the duration of my connection.
I got a bit confused on which parameter I should pass, having originally thought the second port would be the local port I need to bind to. After extensive experimentation on port configs I am at a loss as to how to handle this.
In addition I tried various overloads but none of the 3 other overloads seemed to produce what I wanted.
Any tips?
Thanks,
Andy
Ok I've resolved this now.
The solution is to modify the MySQL connector string so it uses a Ephemeral port. Picked one at random.
server=localhost; uid=;pwd=; database=; port=14324
Then modify the ForwardedLocalPort to bind to this port.
ForwardedPortLocal port = new ForwardedPortLocal("localhost", 14324, "localhost", 3306);
So we're forwarding the connection to localhost 14324 to localhost 3306 on the remote server.
Next challenge how to ensure that the port I use isn't already bound!!
So to do this use the overload that does not require a port number i.e.
ForwardedPortLocal("localhost", "localhost", 3306)
This will allocate an available Ephemeral port to your process which can be found using:
port.Start();
var portNumber = port.BoundPort;
This can then be added to your MySQL connection string.

No connection could be made because the target machine actively refused it C#

I tried to play around with malware stranger sent me. I open it in vmware and run microsoft network monitor
screenshot
So I tried to make tcp connection using C# like this:
TcpClient tcpclnt = new TcpClient();
Console.WriteLine("Connecting.....");
tcpclnt.Connect("darcometweb.no-ip.org", 225);
tcpclnt.Close();
but it throws exception: Message "No connection could be made because the target machine actively refused it 95.244.217.192:225"
To make sure I also tried it in Python but it also throws the same exception
import socket
s = socket.socket()
host = 'darcometweb.no-ip.org'
port = 225
s.connect((host,port))
s.close
print 'done'
Anyone knows what is wrong ?
# Syed Ali Taqi: I have looked into that question, however in my case the malware can make connection but my c# app can't
Usually happens when the port is closed/ no port forwarding on the router/ firewall or anti virus blocking the connection.
First open command line and type
netstat -a
to see all the open connections and ports, if your port listed then go to
Open port checker and type in your port to see if there is an access from outside your network.
If no i would go with port forwarding then, windows firewall, anti virus.

C# console app won't send UDP multicast packet on Windows Server 2003

I can't seem to get my little test app to send a UDP multicast packet on a particular machine running Windows Server 2003. I have it setup to send a packet to Google's public DNS and another to 239.192.250.250. It runs fine without throwing any errors. But in the Wireshark output, only the Google packet shows up. Any ideas?
static void Main(string[] args)
{
var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
var data = ASCIIEncoding.UTF8.GetBytes("hello world");
socket.SendTo(data, new IPEndPoint(IPAddress.Parse("8.8.8.8"), 80));
socket.SendTo(data, new IPEndPoint(IPAddress.Parse("239.192.250.250"), 80));
Console.ReadKey();
}
And here's the Wireshark output:
No. Time Source Destination Protocol Length Info
205 1.83925300 ********** 8.8.8.8 UDP 53 Source port: 62432 Destination port: http
On every other machine I've tested including a Windows 2008 R2 server, I get something to the effect of:
No. Time Source Destination Protocol Length Info
58 4.52926800 ********** 8.8.8.8 UDP 53 Source port: 56530 Destination port: http
60 4.52940400 ********** 239.192.250.250 UDP 53 Source port: 56530 Destination port: http
If you are on a Network switch, they only routes the packet to the connection of the destination machine. Whereas an unswitched hub broadcast packets to all ports.
Wireshark does packet sniffing therefore it cannot see all packets on a switched router.
Here is excerpt from Switch Reference # Wireshark:
As noted in the Wireshark FAQ, capturing in a switched network environment can prove to be challenging. An individual switch port will receive broadcast, multicast, and unicast traffic destined for that particular port. In most cases it won't receive unicast traffic for other ports, which is what you're probably trying to capture.

Why does my "remote" machine have an ESTABLISHED connection to my dev machine?

I have created a simple "proof of concept" app that sends a text message over sockets using C# between two Windows computers (XP sending, W2K receiving).
When I run "netstat -a" on the receiving computer, I see a couple of strange things:
netstat tells me:
...
TCP <thismachinename>:netbios-ssn <DevMachineName>:1330 ESTABLISHED
...
--and:
TCP <thismachinename>:1041 a65.197.244.82.deploy.akamaitechologies.com:http CLOSE_WAIT
So:
1) Why is there a connection with my Dev machine (It SHOULD be listening on port 62222, but it's not, yet this mysterious ESTABLISHED connection does exist...)
2) Who/what/why is this akamai technologies connection?
Note: I restarted the remote/listening machine this morning; I checked netstat -a to be sure it was not listening on port 62222 yet (it wasn't); I then started the dual-purpose app that should listen on that port; I ran netstat -a again, and it was STILL not listening on port 62222. Yet these other two odd things...
The established connection to <thismachinename>:netbios-ssn is because you have connected to a Windows Share, printer or something on thismachinename from DevMachineName.
The second connection is that your computer has for some reason connected and downloaded something from akamai. The connection is closed, but in CLOSE_WAIT mode which it is for 120 seconds (if I remember the timeout correctly).
For the listening on port 62222 that is not appearing - do you get any errors in your app when you are opening the listening socket?

TCP connection lost problems in c#

In my application, I have a server listening on a port on localhost for client connection. Then I have clients running and establishes connection with the server. I used tcpListner in c# for the server and the clients were written in perl using Inet function.
The connection between clients and server were established without a problem and a message from client is received by the server. However, after about 3 to 4 seconds, the connection is lost. I use netstat -a to see if the status of the connection is still "established". The result is "Close_wait" after I use netstat command on DOS.
How can I debug this problem? Which side is causing the lost of connection?
Thanks
Edit:
$tx_socket = IO::Socket::INET->new( PeerAddr => '127.0.0.1', PeerPort => 9000,
LocalPort => 8000, Proto => 'tcp',
Type =>SOCK_STREAM, Reuse=>1 ) or die("$!\n");
die("init_tx_socket failed!\n") unless $tx_socket; print "Socket good!\n";
$tx_socket->autoflush(1); $tx_socket->print("Hello");
sleep(5);
$tx_socket->print("World");
Capturing network packets with Microsoft Network Monitor or Wireshark, or use System.Net tracing.
Socket issues cannot be easily analyzed and handled without such analysis.

Categories