× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.




..ah, thanks for that, I was expecting the http server to trap the end of QSH itself and close gracefully.

Tim.

________________________________
From: WEB400 <web400-bounces@xxxxxxxxxxxx> on behalf of Kevin Turner <kevin.turner@xxxxxxxxxxxxxx>
Sent: 17 March 2017 12:10
To: Web Enabling the IBM i (AS/400 and iSeries)
Subject: Re: [WEB400] NodeJs hung ports

Of course there is a close() method: https://nodejs.org/api/http.html#http_server_close_callback
HTTP | Node.js v7.7.3 Documentation<https://nodejs.org/api/http.html#http_server_close_callback>
nodejs.org
An Agent is responsible for managing connection persistence and reuse for HTTP clients. It maintains a queue of pending requests for a given host and port, reusing a ...




You are just using a simple bare bones example. In the real world you wouldn't run a server or daemon from a windows CLI or from QP2TERM interactively on the IBMi. On the former it would probably be a service and on the latter a submitted job (or similar). You therefore need a graceful way to end the server. The common way would be to send SIGTERM and then cater for that in your server:

process.on('SIGTERM', function () {
server.close(function () {
console.log("Shutting down after SIGTERM");
process.exit(0);
});
});

You can send SIGTERM by running the kill() method on the process (if you have a handle to it). If, on the IBMi, you are simply going to end the job you might have to handle SIGINT also (as above):

process.on('SIGINT', function () {
server.close(function () {
console.log("Shutting down after SIGINT");
process.exit(0);
});
});


-----Original Message-----
From: WEB400 [mailto:web400-bounces@xxxxxxxxxxxx] On Behalf Of Tim Fathers
Sent: 15 March 2017 13:20
To: Web Enabling the IBM i (AS/400 and iSeries) <web400@xxxxxxxxxxxx>
Subject: Re: [WEB400] NodeJs hung ports


There isn't a close method, once you call server.listen(...) that's it, in Windows it's ended with Ctrl-C. The simplified code is below, lifted from the examples:

var http = require('http'),
httpProxy = require('http-proxy');

var proxy = httpProxy.createProxyServer({"changeOrigin": true});

var server = http.createServer(function(req, res) {
// You can define here your custom logic to handle the request
// and then proxy the request.
proxy.web(req, res, { target: 'http://ger400-d:13482' }); });

console.log("listening on port 5052")
server.listen(5052);

Tim


________________________________
From: WEB400 <web400-bounces@xxxxxxxxxxxx> on behalf of Kevin Turner <kevin.turner@xxxxxxxxxxxxxx>
Sent: 15 March 2017 14:03
To: Web Enabling the IBM i (AS/400 and iSeries)
Subject: Re: [WEB400] NodeJs hung ports

Presumably you are calling the "close" method when you want to end? If you are just killing the shell then you need to trap that and close the connection gracefully - but preferably have a cleaner way of terminating.

[https://www.netcracker.com/assets/img/netcracker-social-final.png] ƕ -----Original Message-----
From: WEB400 [mailto:web400-bounces@xxxxxxxxxxxx] On Behalf Of Tim Fathers
Sent: 15 March 2017 09:34
To: web400@xxxxxxxxxxxx
Subject: [WEB400] Fw: NodeJs hung ports

Hi all,


I'm trying to create a simple reverse proxy to front our application servers using this https://www.npmjs.com/package/http-proxy but I'm finding that after I execute it through the QP2TERM shell the port number is still in use after the shell session ends. Netstat shows no jobs or tasks associated with the port, but it does show my user profile as being the associated user. Is there a) a way to prevent this happening, b) a way to forcibly free the ports that appear to be hung?


Many thanksm


Tim.

[https://www.npmjs.com/static/images/touch-icons/open-graph.png]<https://www.npmjs.com/package/http-proxy>

http-proxy - npm<https://www.npmjs.com/package/http-proxy>
www.npmjs.com<http://www.npmjs.com>
node-http-proxy node-http-proxy is an HTTP programmable proxying library that supports websockets. It is suitable for implementing components such as reverse proxies ...


--
This is the Web Enabling the IBM i (AS/400 and iSeries) (WEB400) mailing list To post a message email: WEB400@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/web400
or email: WEB400-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at http://archive.midrange.com/web400.




________________________________
The information transmitted herein is intended only for the person or entity to which it is addressed and may contain confidential, proprietary and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.
--
This is the Web Enabling the IBM i (AS/400 and iSeries) (WEB400) mailing list To post a message email: WEB400@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/web400
or email: WEB400-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at http://archive.midrange.com/web400.


[https://www.netcracker.com/assets/img/netcracker-social-final.png]
--
This is the Web Enabling the IBM i (AS/400 and iSeries) (WEB400) mailing list To post a message email: WEB400@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/web400
or email: WEB400-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at http://archive.midrange.com/web400.



________________________________
The information transmitted herein is intended only for the person or entity to which it is addressed and may contain confidential, proprietary and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.
--
This is the Web Enabling the IBM i (AS/400 and iSeries) (WEB400) mailing list
To post a message email: WEB400@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/web400
or email: WEB400-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/web400.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.