I'm writing a WIntRt application in C# and I use StreamSocket.
The fragment of code I have problem with looks like this
try
{
await StreamerConnection.socket.ConnectAsync(new Host("192.168.10.14", "8777");
}
catch(Exception ex)
{
ex.ToString();
}
My problem is that when remote host is inaccessible, my program instead entering the catch block, exists from function in which the try..catch block is. How can I handle situation when remote host is inaccessible and StreamSocket cannot connect to that host? How can I determine that it could not connect because destination host was unreachable?
Related
I have built Poco 1.11 and am unable to get secure SMTP connections, or HTTPS connections in general, to work, with the NetSSL_Win module (i.e. using Windows Schannel rather than OpenSSL). There is a sample in the distribution at NetSSL_Win\samples\Mail\src :
SecureSMTPClientSession session(mailhost);
session.login();
session.startTLS(pContext);
if ( !username.empty() )
{
session.login(SMTPClientSession::AUTH_LOGIN, username, password);
}
session.sendMessage(message);
session.close();
When I run it, the second login() call, after the startTLS() call, throws this error:
SSL Exception: Failed to decode data: The specified data could not be decrypted
The server in this case was smtp.gmail.com, on port 587.
I get the same error message for any other HTTPS client code I try to run as well.
Is anyone successfully using Poco 1.11 for HTTPS connections, using Windows Schannel?
how can i simulate the "PROTOCOL_CONNECTION_LOST" error in mysql for node.js?
If i get the error, my application crashes, and i dont know how to reproduce this error.
thank you.
it really sounds like your application is crashing because is not handling the error. You may want to check in the files where you initialize the MySQL connection if that's the case.
As for the error, the "PROTOCOL_CONNECTION_LOST" is just a Generic Error Object. If you want to throw it inside your application (not actually stopping MySQL from working):
const err = new Error('Connection lost: The server closed the connection.');
err.fatal = true;
err.code = 'PROTOCOL_CONNECTION_LOST';
throw err;
Put that in the line of code where you want to throw the error.
If you want to emulate that MySql is throwing this error, one (unrecommended way) is to hack into the lib. The Connections object has access to the Protocol object, which has a hidden method _delegateError that's the one fired when there's a protocol error. Source: https://github.com/mysqljs/mysql/blob/master/lib/protocol/Protocol.js
Here is solution for connection protocol lost. This solution solved me
Here the data base connection
const mysql = require('mysql');
const connection=mysql.createConnection({
host:'localhost',
user:'root',
password:'******',
database:'db_name'
});
connection.connect(function(error){
if(!!error) console.log(error);
else console.log('SQL Database Connected!');
});
module.exports = connection;
`
just run the node server using pm2
Ex. pm2 start app.js
install the npm pm2 package
I have a UWP app using C#. I use HttpClient to retrieve a JSON file from the server. On some machines however it fails with a "unable to connect to the remote server". The server is accessible through the browser though. Any ideas?
The HttpClient has a Timeout property. Set that to the timeout you want and handle the TimeoutException to do specific things on the timeout.
HttpClient client = new HttpClient();
client.Timeout = TimeSpan.FromSeconds(5);
HttpResponseMessage response = null;
try
{
response = await client.GetAsync(url);
}
catch (TimeoutException)
{
// handle the timeout, e.g. return false
return false;
}
catch (Exception ex)
{
// handle the other errors, e.g. throw it
throw (ex);
}
I have made a JSP website in NetBeans which I tried and tested on my local server through tomcat(using access database) and it worked fine. My web host has provided me the host, database name, username and password of the database. I want to configure my website to use this database. But I don't know how to do that. I have seen the system.properties file in web-inf/config folder whose content are like this:
JNDI_NAME=java:com/env/Oracle/jndi
db.login=
db.password=
driver=sun.jdbc.odbc.JdbcOdbcDriver
url=jdbc:odbc:mydb
duser=
dpass=
logfile=log/aoc_log.txt
dbname=my_db
But I am confused how to modify this file. Also, the database is only accessible from the web host.
Below code shows how connection is made (I think so...)
public Connection getConnection()
{
try
{
if(con==null)
{
try
{
Properties p = getProperties();
Class.forName(p.getProperty("driver"));
System.out.println("Driver loaded");
con = DriverManager.getConnection(p.getProperty("url"),p.getProperty("duser"),p.getProperty("dpass"));
System.out.println("Connection established");
}
catch (ClassNotFoundException cnf)
{
LoggerManager.writeLogWarning(cnf);
}
}
}
catch (SQLException sqlex)
{
sqlex.printStackTrace();
LoggerManager.writeLogSevere(sqlex);
}
return con;
}
I finally figured it out. In the java code above the function "getProperties()" fetch the 'system.properties' file from "web-inf/config" folder. It can be noticed in the 'system.properties' file that the driver used is for making an odbc connection. But mine is a MySQL database and hence we have to replace the driver with 'com.mysql.jdbc.Driver'. The url will be changed as 'jdbc:mysql://192.168.0.1:3306/' where 192.168.0.1 is the host and 3306 is the port. Add your database name in dbname field, username in duser field and password in dpass field. Save and redeploy the project and it gets connected.
I am trying to use SignalR client side libraries on HTTPS server. It works fine on normal server but on HTTPS server, it is throwing an exception.
try
{
...
hubConnection = new HubConnection(signalUrl);
proxy = hubConnection.CreateHubProxy("SignalRConnect");
hubConnection.Start().Wait(); // throws an exception at this line
...
}
catch (Exception ex) {
I am getting exception - "The remote certificate is invalid according to the validation procedure."
}
Does anybody has an idea how to configure client side SignalR?
Thank you in advanced.
Medha
If your server requires custom client certificates then you can use SignalR 1.1 beta to add an x509certificate to the connection before the request is made.
Issue is resolved. I removed the code of creating proxy from the controller and add code on client side and get context of the hub from controller code.
var hubContext = GlobalHost.ConnectionManager.GetHubContext();
and use hubContext for client notification.