Check remote host state in a nework using Indy comps - c++

I have client server application that works with Firebird server. Everytime when clients connect to the server they(client apps) don't check if there is a network connection to the server so at this time my application sometimes freezes when the server computer is switched off or service has stopped, so first of all I need to check connection if remote host is switched on or at some port anything listening....
Before establishing the connection I need to check it and make sure server and service is running using Indy components.
Any ideas? also I can use IcmpClient to ping remote host and then establish connection but which is the most optimal way ?

If you just want to check if the server computer can be reached, you could do a "ping" to check that. However, if you want to check if a specific TCP port is open, then the only way to find that out is to actually do a proper connect, which leads to the "freezing" program while the connection times out if there is no-one listening on that port.

Related

Slow Connect via Open / OpenAsync .Net Provider Unidata

I am consistently seeing a 3+ second delay when opening a connection to a Unidata server via OpenAsync and the ADO.NET provider by Rocket.
What can I do to diagnose this delay?
I use jdbc and odbc connections all the time, and three seconds just ain't right.
You can start by breaking things down into client, network, server.
On the client, is it the same if you use an IP address vs hostname? If different, then DNS delay. Do you have any antivirus or other software that might be delaying connections? Can you turn that off, or do a test from a freshly configured machine?
For network, can you ping the unidata server in millseconds? Are there firewalls in the way? Can you install wireshark and filter packets by destination? Is there a delay when you ssh? Is the server configured with LDAP/AD, or local authentication - could be connecting to another server to authenticate?
On the server, you can turn on uniobjects logging, then restart unirpcd. Do you have something in your LOGIN/UOLOGIN that is hanging up the remote connection?
$cat $UDTHOME/serverdebug
udcs 9 /tmp/udcs.log

OS X IPC get process-ID in C

Is there any server-client like inter-process-communication method which allows:
the server to reliably get the process-ID of a connected client
any client-application to connect to the server
works in C/C++
Optionally: Works also on Linux
Since your server runs with root rights, you can work with task_for_pid() and a two way connection. First, the client will send its pid to the server via some special bootstrap port on the server, the server will then resolve the pid via task_for_pid to a task port and then use mach_port_insert_right to insert a send right to a new port into the client. The new port is then exclusively to the client and you know what security level the client has.

Find DBus server by broadcast (or otherwise)

In my Qt application I am using a peer to peer DBus connection. Server runs on computer A, client on B, connected via DBus TCP/IP connection. Works fine.
I wonder if I can somehow find out whether the server is running and what its IP address is? So far I need to provide the correct address/port in the client.
Both, server and client run in a local network. Of course, I can use a trial and error approach and ping all machines in my network. Is there something better, something like a broadcast asking for the server, and the server responding appropriately? Is Qt providing something for this?

How to detect mysql server down status quickly

I have an application which connects a remote database server.
If mysql server stops for a reason and stars succesfully after that, my application cannot detect server status quickly. It takes nearly 20 seconds to reconnect to the database server. So my gui freezes. I do not want a gui freeze for 20 seconds
So far I tried
mysql_ping
mysql_real_connect
functions
MYSQL_OPT_RECONNECT
MYSQL_OPT_CONNECT_TIMEOUT
options
My enviroment is not multi-threaded. So
how to do a faster detection?
If you do networking synchronously, be prepared for freezes. For this very reason it makes sense to do data-manipulation in a separate thread.
You could try telnet to the mysql port (usually 3306). If you get a connection refused, mysql isn't listening.
Working.
root#XXXXXX:~# telnet localhost 3306
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
L
5.6.4-m7)#m#_8:W�hP5YBzaXs[MOmysql_native_password
Down.
root#XXXXXX:~# telnet localhost 3306
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused
The refused message is almost instant.
As already discussed by others, i won't talk about using multiple threads or processes. Can you connect to your mysql server on tcp? That way in most scenario's you would receive a tcp fin immediately to indicate a closed connection, though at times this might not be the case even. But most robust applications do a proper close.
shell> mysql --protocol=TCP
MYSQL how to specify protocol
If server doesn't accept it, i believe it can be enabled from config settings.
However, this does not address scenarios such as server suddenly gets off the network, or you client's connection is down etc.

How to detect whether a remote computer is running RDP?

How do I detect if a remote client is running Remote Desktop Protocol? and it is also accepting remote desktop connections ??
Like Open an port to detect HTTP and send request, receive request headers and see in request headers information about HTTP so I will know the person is running HTTP weather if he changed the port e.g: running HTTP 6551.
Attempt and make a connection with something that is RDP-connection aware (RDP is not HTTP). Of course, failing to establish an initial handshake is not proof that a connection can not be established. It could be blocked by a firewall, listening on another port, etc.
The MS-RDPBCGR specification, page 16 talks about connecting which in turn defers to X.224, go figure.
It'd likely just be easiest to use Wireshark and observe in-the-wild behavior to develop a minimal detection case. I suspect only the very initial portion of the handshake needs to be generated/replayed in order to "decide" that it's a listening RDP server.
(Or, perhaps use an existing RDP client which has this "test connect" functionality or the ability to be scripted.)
A fast way is to pen a shell and type
telnet IPADDRESS 3389
If you get a connection, chances are good that an RDP server is on the other side. RDP can run on any port, but TCP Port 3389 is set per default.
Windows 7 requires some extra steps to enable the telnet Client.
You could do netstat -a in the command line and see if the default port for remote desktop connection is listening, ie. TCP:3389 but thats only if the client hasn't changed the ports for MSTSC