How VNC Disconnects the already connected RDP Session - vnc

While using VNC combined with RDP, I have noticed a behaviour which VNC do, that is when you have connected to a machine using RDP (mstsc), and then you want to connect to that machine using VNC, it will disconnects the RDP session, and you will see a screen blink(Black screen for a second) on the target machine and then you are connected via VNC, What I want to know is that How VNC is disconnecting the active RDP sessions, Any code snippet will be really help ful..
Thanks

When you connect using VNC it tries to connect to the console session using WinStationConnectW (Which is undocumented) this will disconnect the RDP session.
Here is a snippet from TightVNC:
void setConsoleSession(DWORD sessionId) {
#ifdef RFB_HAVE_WINSTATION_CONNECT
if (!_WinStationConnect.isValid())
throw rdr::Exception("WinSta APIs missing");
if (sessionId == -1)
sessionId = mySessionId.id;
// Try to reconnect our session to the console
ConsoleSessionId console;
vlog.info("Console session is %d", console.id);
if (!(*_WinStationConnect)(0, sessionId, console.id, L"", 0))
throw rdr::SystemException("Unable to connect session to Console", GetLastError());
// Lock the newly connected session, for security
if (_LockWorkStation.isValid())
(*_LockWorkStation)();
#else
throw rdr::Exception("setConsoleSession not implemented");
#endif
}

Related

NodeJS WebSockets routing messages from devices to Angular gui through NodeJS

I've created a NodeJS application that implements a socket manager like so:
import { Server } from "ws";
import clientObj from "../objects/clientObj";
import serverObj from "../objects/serverObj";
class socketMgr {
serverA = undefined;
serverB = undefined;
confA = undefined;
confB = undefined;
init(cA, cB) {
this.confA = cA;
this.confB = cB;
}
serve()
{
// server between devices and nodejs
if (this.confA.host && this.confA.port)
{
this.serverA = new Server({ host: this.confA.host, port: this.confA.port });
this.serverA.on("connection", connection => new clientObj(this.confA, conn));
}
// server between nodejs and gui
if (this.confB.host && this.confB.port)
{
this.serverB = new Server({ host: this.confB.host, port: this.confB.port });
this.serverB.on("connection", conn => new serverObj(this.confB, conn));
}
return true;
}
}
export default socketMgr;
This manager declares and initializes two socket servers that send and receive messages. The whole flow goes like this (simplified on a 1 to 1 approach):
device (clients written in native C++ or other, no GUI) <==> NodeJS client/server <==> gui client (devices running Win, iOS or Unix based OS)
device connects to NodeJS and creates a client (that implements event listeners) on serverA
client on serverA replies to the handshake request from the device
when handshake is successfull, device starts emmiting messages periodically to NodeJS (client on serverA)
NodeJS client processes messages and saves some states to the DB (sql), not entire messages because that would be an absolute overkill
TODO:
Once a message is processed on the serverA client, that message has to be emmitted somehow to the corressponding gui client (hosted on a different port).
This is the fun part where web sockets serverB comes into place. I don't really know if this is the right approach but I'd like to use ServerB instance to re-route/broadcast to the gui. Many devices (hundreds or even thousands) will eventually send messages like this and many users can watch these messages from the gui side (monitoring).
Can re-routing/broadcasting messages to the gui be achieved without the serverB instance?
How can I achieve this type of re-routing/broadcasting of messages in NodeJS?
EDIT: This issue is a lot more complicated than my first estimation showed. Devices have to communicate through two web socket servers and connections must be managed seperatelly because these devices on both sides aren't equal in any way. Routing between them must be handled programmatically.
If I can provide any additional info. on the subject, please let me know.
Thank you for looking into this.
Best Regards.
You dont need to create two server for this. Device and GUI both is client. When device emits data to server you can send this data to GUI by allowing subscribing GUI client to device messages, by topic name or by device ID.

Connection to external postgres database times out

I am trying to connect a client device to a PostGreSQL host device. I have 2 devices with PostGreSQL on them: A Windows OS device (Host) and a RaspberryPi running raspbian (Client).
I have pgAdmin on the host device, with a PostGreSQL server running on it (The server is the default PostGreSQL server with default configurations).
The host device and the client device are on the same network (wifi).
I have the following node.js code on the client device:
const { Client } = require('pg');
const connectionString = 'postgres://postgres:MyPassword#192.168.1.8:5433/postgres';
const client = new Client({
connectionString: connectionString
});
client.connect();
client.query('CREATE TABLE test (something text, number int)', function(err,result){
if (err) throw err;
console.log(result);
console.log('hi');
});
based on the code above, the client would connect and query the making of a table, then return the result and 'hi' in the command line.
When I run it, it does nothing. After a minute or so, the connection times out.
Is there anything that I'm missing?
I used Wireshark to see if the client device was even sending packets. The client device was sending packets (directed to the postgresql post), so my assumption is that the problem is with the host device, but I don't know why because I have already edited the configuration files multiple times by now.
I have already...
changed config files
restarted the system
re-installed the software
switched to trying to connect from psql
Well, this is interesting...
So I found the real .config files on the host device, and I changed listen_addresses = '*' to listen_addresses = '192.168.1.12'.
After I made those changes, I tried to restart postgres and then the service stopped, but refused to be started again. I opened pgAdmin 4, and none of the servers were wanting to connect. After I changed the file back to listen_addresses = '*' the service started and everything was back to normal. My conclusion now is that there is a problem with the firewall. Does anyone here do Windows and can help me configure the firewall??
Turns out, I was bothering myself with the Postgres configuration files, but I had to look at the firewall configurations. Those were the ones that were blocking the pi. If anyone has the same problem, I suggest looking at your firewall first. (Specifically allowing port 5432)

Run a VPN client on a remote website

I have been researching this for day and I haven't been able to find the way to do this.
I am building a react app, running express at the backend, that needs to access some data in a remote database that lives inside a VPN. At the moment the app lives on my localhost so its enough for me to connect my machine using openvpn client and everything works a beauty. The problem will rise when the app will be live and I will need it to have access to the vpn by (I'm guessing) having a vpn client running on the site/domain.
Has anyone done this before?
I have tried to install the node-openvpn package that seems could do the job but unfortunately I can't manage to make it work as the connection doesn't seem to be configured properly.
This is the function I call to connect to the vpn that systematically fails at the line
--> openvpnmanager.authorize(auth);
const openvpnmanager = require('node-openvpn');
...
const connectToVpn = () => {
var opts = {
host: 'wopr.remotedbserver.com',
port: 1337, //port openvpn management console
timeout: 1500, //timeout for connection - optional,
logpath: '/log.txt'
};
var auth = {
user: 'userName',
pass: 'passWord',
};
var openvpn = openvpnmanager.connect(opts);
openvpn.on('connected', function() {
console.log('connecting..');
openvpnmanager.authorize(auth); <-- Error: Unhandled "error" event. (Cannot connect)
});
openvpn.on('console-output', function(output) {
console.log(output)
});
openvpn.on('state-change', function(state) { //emits console output of openvpn state as a array
console.log(output)
});
};
Am I misusing this function? Is there a better way?
Any help will be extremely appreciated.
Thank You!
The problem will rise when the app will be live and I will need it to
have access to the vpn by (I'm guessing) having a OpenVPN client running
on the site/domain.
Thats correct, you will need an openvpn client instance on the server where you will run the backend.
The above library (node-openvpn) is simply a library to interact with the local OpenVPN client instance. It cannot create a connection on its own. It depends on the OpenVPN binary (which should be running).
The solution you need is simply run the OpenVPN client on your server (apt-get openvpn). And let the daemon run. Check out the references below.
node-openvpn issues that points out that a running instance of the client is needed
OpenVPN CLI tutorial

node-serialport only communicates with Arduino if another app has already connected to the port

Running on node in OS X, I am trying to use node-serialport to talk to an Arduino. All communication to the Arduino works as expected when using Arduino IDE's Serial Monitor, or the OS X utility SerialTools. However, when just running my node app, node-serialport tells me the connection is successful, but I get no communication. If I first make a connection to the arduino with Arduino IDE's Serial Monitor or SerialPorts, then run my node app, the node app sends and receives data just fine using node-serialport.
I'm not familiar with serial communication, but it seems like the other serial utilities are able to properly start a connection (which is then available to node-serialport), but node-serialport is not able to connect on its own.
Is there a way to get absolutely all connection information, so I can compar the utilities' successful connections to node-serialports non-working connection?
Any other ideas as to why this would be happening?
I have a working solution, but unfortunately not a complete explanation. Reviewing some related issues such as What's going on after DTR/RTS is sent to an FTDI-based Arduino board?, I determined that even just restarting the node app (rather than requiring another serial connection app) gave node the ability to communicate through the serial port. I'm beyond my depth, but I suspect that initially establishing the RTS connection restarts the arduino, and only after that happens can node-serialport communicate through the connection.
My workaround is to simply give the Arduino some time to reset before attempting a second serialport connection, which works.
var firstConnect = true;
serialPort.open(function (error) {
if (firstConnect){
firstConnect = false;
//First connection, letting Arduino reset
setTimeout(function(){serialPort.open()},4000)
} else {
//Second connection, which will work
serialPort.on('data', function(data) {
//data parsing function
//...
}
}
});

How to keep long-lived connections between a Chrome extension and a native messaging host?

I created a Chrome extension and use Native Messaging to connect to a C++ native application.
But for every message that the Chrome extension sends to the native host, a new host exe instance is created. I think it is not efficient because I send many messages to the host.
Is there a long-lived connection method between a Chrome extension and a native messaging host?
If you are sending the messages with chrome.runtime.sendNativeMessage, or create a new Port object with chrome.runtime.connectNative for every message, then yes, it's inefficient.
The purpose of chrome.runtime.connectNative is to create and maintain open a message Port, which you can reuse. As long as your native host behaves in a manner Chrome expects and doesn't close the connection itself, it will be a long-lived connection.
function connect(messageHandler, disconnectHandler){
var port = chrome.runtime.connectNative('com.my_company.my_application');
if(disconnectHandler) { port.onDisconnect.addListener(disconnectHandler); }
if(messageHandler) { port.onMessage.addListener(messageHandler); }
return port;
}
var hostPort = connect(/*...*/);
port.postMessage({ text: "Hello, my_application" });
// Goes to the same instance
port.postMessage({ text: "P.S. I also wanted to say this" });
// If you want to explicitly end the instance
port.disconnect();

Resources