Is there any way to detect when a Remote Desktop Connection is starting on a Windows machine?
For example, I'd like to have a c++ application print "WARNING: RDC Connection incoming" as soon as Windodws detects that a RDC connection has been initialized.
Is there some sort of system event that is called when RDC connects?
you can create a thread that will keep asking if a remote connection is opened right now every 500 ms,you can find how to do it right here.
you still might not caught it in time so you can check which TCP ports get open every small interval of time, you can use GetTcpTable2 for this look at https://msdn.microsoft.com/en-us/library/windows/desktop/bb408406(v=vs.85).aspx.
specificly you should check the state of the port.
since the first thing that happen in a remote connection is the port changing is state you should catch it in time.
The RDP port is 3389.
Related
I want to write a simple program in c++ that use tcp socket to communicate with the same program on another computer in lan.
To create the tcp socket I could make the user write the ip and the port to make the connection. But I also need to be able to autodetect in the local area network if there is any computer also running the program.
My idea was:
when the program is autodetecting for available connection in lan, it will send all ips a message via udp to a specific port, meanwhile it will also keep listening to a port waiting to eventual answer.
when the program on the other computer is opened for lan connection, it will keep listening to the a port in case another computer is trying to detect, then it will send also via udp the response messagee notifying the possibility of connection.
All the security system is another problem for which I don't need answer now.
// Client 1:
// Search for all ips in local network
// create udp socket
// send check message
// thread function listening for answers
// if device found than show to menu
// continue searching process
// Client 2 (host) :
// user enable lan connection
// create udp socket
// thread function listening for detection requests
// if request structure is right send back identification message
// continue listening for request
My question - Is there a more efficient or standard way to do something like that?
Testing whether another computer is listening on a given port is what hackers do all day to try to take over the world...
When writing a software like you describe, though, you want to specify the IP and port information. A reason to search and automatically find a device would be if you are implementing a printer, for example. In that case, as suggested by Hero, you could use broadcasting. However, in that case, you use UDP (because TCP does not support that feature).
The software on one side must have a server, which in TCP parlance means a listen() call followed by an accept() until a connection materialized.
The client on the other side can then attempt a connect(). If the connect works, then the software on the other side is up and running.
If you need both to be able to attempt a connection, then both must implement the client and server (which is doable if you use ppoll() [or the old select()] you know which event is happening and can act on it, no need for threads or fork()).
On my end, I wrote the eventdispatcher library to do all those things under the hood. I also want many computers to communicate between each others, so I have a form of RPC service I call communicatord. This service is at the same time a client and a server. It listens on a port and tries to connect to other systems. If the other system has a lower IP address, it is considered a server. Otherwise, it is viewed as a client and I disconnect after sending a GOSSIP message. That way the client (larger IP address) can in turn connect to the server. This communicator service allows all my other services to communicate without having to re-implement the communication layer between computer over and over again.
I have a patching program for a game and before the button to open the game is able to be clicked I am wanting it to check that the server is actually online which has a static ip address and port that is used and never changes. Right now it checks if there are any patches before the play button is activated but I want it to also check if the server is online.
I've already been searching but perhaps I've not been using the right terminology.
Basically I don't need it to show any messages just check if the specific port is listening.
Have you just tried connecting?
TCP uses a three-way handshake: SYN, SYN-ACK, ACK. You don't need to know the exact details, your OS will handle it if you connect. And if the other side does not have its port open, it won't reply with that SYN-ACK. Your OS will time out and inform you that the other side ignored you.
I am working on project having client server architecture. select function returns different value in different scenarios Followings are the details
Scenario 1:
When i install my server at my machine, stop all the corresponding services, my client goes to DC state and now return value of select is 1 and read_mask.fd_count is also 1.
Scenario 2:
When i connect to remote server (abc.com) and disconnect my wireless connection. in this case the same function returns 0 also read_mask.fd_count is 0. i tried changing timeout variable value from ten ms to 50 sec. cant figure out the problem.
Any help will be appreciated
When you shot down the server you cause the network stack to shutdown the connection. Furtehr connection request are refused. The select indicates that there's something and the the recv() returns 0 to indicate forcibly closed.
When you pull the wireless cable out of the plug then the client gets neither the shutdown nor the connection request. You wait for any timeout to detect the not available server.
In a real world application you should implement a kind of heartbeat in you protocol that allows to detect the "disconnected state" in the second scenario.
Edit: If your Winsock implementation supports SO_KEEPALIVE_VALS, you can also configure this to detect the lost connectivity. See also: SO_KEEPALIVE.
While trying to connect get error:
"No connection could be made because the target machine actively refused it."
But netstat shows:
TCP 0.0.0.0:MY_PORT MY_PC:0 LISTENING
Only problem what i can think is what app bound to the port is under step-by-step debugging, so it is paused. How i can workaround it.
Basicly i need to know somehow if somebody already bound to a port. (i can't use SO_EXCLUSIVEADDRUSE)
i think i can't connect because app what uses port is in debug paused mode, so, first time i connect then it doesn't "clear connection".
If you just want to check if a given port is in use, you can bind() to it and check for failure. If you don't want to create a socket and bind it, then you can instead loop through the arrays returned by the GetTcpTable(), GetTcpTable2(), GetTcp6Table(), GetTcp6Table2(), GetUdpTable(), and GetUdp6Table() functions. The Table2() not only report the IPs and Ports in use, but also the Process IDs that own them (from which you can then access additional information, like file names). These are the same functions that netstat uses internally to get its information.
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.