I have Java ME Application that uses HttpConnection API, Here I am easily able to make connection with Proxyless server. But my Question is How can I Connect to any Live Server which uses Proxy Connection?. Do I need to specify Proxy IP & port into my Java ME Code?
Try
HTTPConnection.setProxyServer("my.proxy.dom", 8008);
HTTPConnection.dontProxyFor("localhost");
HTTPConnection.dontProxyFor(".mycompany.com");
AuthorizationInfo.addBasicAuthorization("my.proxy.dom", 8008, realm, user, passwd);
...
HTTPConnection con = new HTTPConnection(...);
For more information on advance connection check http://www.innovation.ch/java/HTTPClient/advanced_info.html
Related
I've created a multiplayer game with websockets in nodejs (using the ws lib), which works just fine. For debugging, I connected to the websocket server with my client webpage by just opening the html file via file:// protocol.
I wanted to have the page hosted on my web-server which uses https. This web-server also uses nodejs, but because the webpage is served via https, it cannot create a connection via ws and needs wss. Security downgrading and so on.
My problem is that I've got two separate programs: the https webserver and the websocket "game" server.
When i try connecting to the ws server i get:
Uncaught DOMException: The operation is insecure.
I only found instructions on how to set up wss by creating a https server, but i already have one.
Do i need to combine the two programs?
Could i maybe just serve the single page for the game with http?
Is there some other technology, which doesn't have these security restrictions? (i don't care about encryption for the websockets)
I was able to make it work:
Instead of wanting to use the https server from the web-server, i "upgraded" my http-server for the "gameserver" to https. I didn't want to "create" another https server, because i thought it would cause errors, but i already made a http server indirectly anyways, with new WebSocketServer.Server({ port: PORT });.
To create the https server and use it for the WebSocketServer i used this code:
let cert = fs.readFileSync(pathtocertkey, "utf8");
let key = fs.readFileSync(pathtopublickey, "utf8");
let options = {key: key, cert: cert};
let server = require("https").createServer(options);
const wss = new WebSocketServer.Server({ server: server});
After that i could listen to any port with server.listen(PORT,callback).
I also wasn't sure how or if i could get the cert i got with greenlock. But I found it undergreenlock.d/live/[yourdomain]/
With greenlock.d being the configDir specified in greenlock.init(options).
For the client i need to connect like this :
ws = new WebSocket("wss://mydomain:"+PORT);'
The following code only works in the browser. It does not work in node.js
let socket1 = io('http://localhost:3031/nsp')
socket1.on("connect", (error) => {
console.log("socket1: connect")
});
I am connecting to a netty-socketio (v1.7.7) java server. I am able to connect to the root namespace on both browser and node.js clients and everything works as expected. However, if I try to connect to a namespace, only the browser client can connect as expected.
Furthermore, I can see on the server that the node.js client (v2.4.0) is connecting to the root namespace when it should be connecting to the named namespace "nsp". As such, the clients join the root namespace and seemingly never join the "nsp" namespace.
On further inspection, the only event I can get to fire on the node.js client, when specifying a namespace, after connecting is "ping" all other events (connect,connect_error,error,reconnect...) never trigger.
Update: the above code works when connecting to a node.js server, so the issue appears to be with the netty-socketio server.
Here is how the netty server is initialized:
Configuration config = new Configuration();
config.setHostname("localhost");
config.setPort(3031);
server = new SocketIOServer(config);
server.addNamespace('/nsp')
I finally figured it out. I had to revert the node.js client version to 1.7.4 (https://www.npmjs.com/package/socket.io-client/v/1.7.4) to get it to work. Not sure why I was forced to use such an old client to be able to use namespaces.
I am attempting to link an app engine service to an instance of SQL Server on the Google Cloud Platform using this documentation
My service is a nodejs application and I am using the mssql library to connect to my database.
The documentation only describes using TCP/IP (an ip address):
const pool = new sql.ConnectionPool({
user: '...',
password: '...',
server: 'localhost',
database: '...'
})
If I try to use localhost or 127.0.0.1 for my server, the connection fails:
I need help with one of the following:
How can I connect to the SQL instance using TCP/IP using the mssql library?
What is the configuration option for the connection pool using unix domain socket?
I haven't actually done this one yet, so I'm guessing a little bit, but try one of these:
Pass the unix socket to the server config tag.
Pass localhost to the server tag and the unix socket value to the port tag.
I am trying to connect to Oracle DB 12c from an electron (nodeJs) application.
I am creating the connection by passing parameters, using the knex library, like this:
knex({
client: 'oracledb',
connection: {
host: hostItems + ':' + connection.Port,
user: connection.UserName,
password: connection.Password,
database: connection.DatabaseName
};
});
In knex the connection parameter is the same as node-oracledb which is used internally.
It works for non-ssl connections like using port 1521, but not for 2484 the standard oracle SSL port. I have the CA certs with me, but I dont know how to pass them.
For the SSL port I get 12547: TNS Lost Contact which sounds about right as it cannot establish SSL connection.
I am trying to figure out how to use SSL with node-oracledb.
The official node-oracledb documentation contains a section describing how to properly configure SSL/TLS.
Since the NodeJS application will be acting as the client in this communication scenario, it must provide the certificates during the handshake (as a browser would for an example).
OK this is very simple to anyone who's used websocket and nodejs.
I have created a websocket server named ws_server.js and put it in C:\Program Files (x86)\nodejs where I have installed the nodejs framework. I started the server and it is running and it says it's listening on port 8080. So far so good, I have the server running.
Now I simply want to connect to it from client code so that I can do all that lovely stuff about capturing events using event listeners etc. The problem is, embarassingly, I cannot figure out what URL to use to connect to my websocket server.
function init() {
testWebSocket();
}
function testWebSocket() {
websocket = new WebSocket("ws://localhost:8080/"); // WHAT URL SHOULD BE USED HERE?
websocket.onopen = function(evt) { alert("OPEN") };
websocket.onclose = function(evt) { alert("CLOSE") };
websocket.onmessage = function(evt) { alert("MESSAGE") };
websocket.onerror = function(evt) { alert("ERROR") };
}
function doSend(message) {
// this would be called by user pressing a button somewhere
websocket.send(message);
alert("SENT");
}
window.addEventListener("load", init, false);
When I use ws://localhost:8080 the only events that trigger are CLOSE and ERROR. I cannot get the client to connect. I must be missing something very simple. Do I need to set up my nodejs folder in IIS for example and then use that as the URL?
Just to reiterate, the websocket server is running fine, I just don't know what URL to use to connect to it from the client.
EDIT: The websocket server reports the following error.
Specified protocol was not requested by the client.
I think I have got it working by doing the following.
var websocket = new WebSocket("ws://localhost:8080/","echo-protocol");
The problem being that I needed to specify a protocol. At least now I get the onopen event. ...if nothing much else
I was seeing the same error, the entire web server goes down. Adding the protocol fixes it but leaves me wondering why it was implemented this way. I mean, one bad request should not bring down your server.
You definitely have to encase it a try/catch, but the example code provided here https://www.npmjs.com/package/websocket (2019-08-07) does not. This issue can be easily avoided.
I just wanted to share a crazy issue that I had. I was able to connect to a websocket of an old version of a 3rd party app in one computer, but not to a newer version of the app in another.
Moreever, even in new computer with the new version of the app, The app was able to connect to the websocket, but no matter what I did, when I tried to connect with my own code, I kept getting the error message that the websocket connection failed
Long story short, They changed an apache configuration that allowed connecting to the websocket via a proxy.
In the old version, apache config was:
ProxyPass /socket/ ws://localhost:33015/ retry=10
ProxyPass /socket ws://localhost:33015/ retry=10
In the new version, apache config was changed to:
ProxyPass /socket/ ws://localhost:33015/ retry=10
By bad luck, I was trying to connect to ws://localhost/socket and not to ws://localhost/socket/. As a result, proxy was not found, and connection returned an error.
Moral of the story: Make sure that you are trying to connect to a websocket url that exists.
For me, the solution was to change the URL from ws:// to wss://. This is because the server I was connecting to had updated its security, and now only accepted wss.