My webapp is over a balanced servers, it works with Tomcat.
These tomcat are on different servers as normal.
In this last days we added a new Tomcat service in the same machine on a different port for our personal tests.
So we have this configuration:
Serv1:8845
Serv2:8845
Serv2:8945
balanced in testmyapp:443 because it is in https.
So when I typing https://testmyapp:443/myapp, I recover the IP of the Serv2 through NetworkInterface, but I don't succeed to recover the port.
I have to know in which port of the server the request is started (8845 or 8945) , because one of this service was created for another purpose.
How can I recover this type of information?
Thank you.
You can access to the listening port with the HTTPServletRequest object, see its getLocalPort method.
By the way, there is a similar method returning the listening IP. NetworkInterface looks somewhat out of context in your case.
Related
I am developing a web application in Java by using RESTful web services and Tomcat. So far I was using the localhost in the URI: http://localhost:8080/3.ServerAPI/rest/Variable. But what if I want to use the real IP?
I have tried that on a local network by replacing the localhost with the LAN IP and it works fine: http://192.168.1.2:8080/3.ServerAPI/rest/Variable
The application at this address received the Variable.
If I want to send this through the internet as long as I know I have to use the WAN IP: http://188.39.25.247:8080/3.ServerAPI/rest/Variable
My question is, if I use the last URI with the WAN IP do I need also to port forward to the LAN IP by configuring the router or it is going to work like when I used the LAN IP ??
Thanks in advance
It depends on your network setup really.
You may have to enable port forwarding on your router to direct the request to the machine that your server is on, also make sure that the router allows connections to port 8080.
I had to do this recently when working with callbacks on external APIs. Seem to remember that I had to enable port forwarding on my router to get it to work. Wasn't too difficult though, just check router instructions on how to do it - like I say, depends on network setup though.
Hope this helps.
I've seen something similar to this and the problem was due to the port being used by another application.
I am using JBoss. The JBoss process binds to ports in a range. My application ran into troubles when setting up remote swing clients with a firewall in between server and client. I want the ability to limit the process to a particular port so I do not have to open as many ports in the firewall.
I want to bind JBoss process to a particular port instead of using a range of ports.
I configured the serverBindPort in server\xxx\deploy\remoting-jboss-beans.xml to 32444.
After this change it looks like Jboss is binding to this port each time server is restarted. But for some reason, it still tries to bind to random port in addition to this.
Are there any other files I need to modify?
Thanks for your help in advance.
JBoss as a container provides a lot of services and some of these services need to bind on sockets. There are some services (like http) that bind on fixed ports while others bind on random ports.
Its easy to control the static ports but for the dynamic ports you need to know which services they are.
This wiki provides all the various ports (static and dynamic). It also provides alternatives (such as HTTPInvoker) to tunnel all the requests through HTTP port.
When I run ActiveMQ by executing the batch file in its bin/ directory, I am able to go to its admin/management console by opening a web browser and going to http://localhost:8161/admin/.
This has me curious.
This is my local sandbox and I do not have any web server (httpd or otherweise) installed. So how is it that ActiveMQ is able to "register" a port on my machine, and listen to it exclusively?
If I try to go to http://localhost:8162/admin/ (notice the different port #), I get an unable to connect error.
Somewhere, somehow, AMQ is saying "map this URI (localhost:8161) to some root directory on this machine". As a programmer, I'm interested in how something like this works.
A Java process is able to use any port (>= 1024 on linux) as a web server or for any other purpose. You don't need a separate web server to do this
I suggest you read up on sockets: here. All a web server is, is a socket listener that handles the HTTP protocol. HTTP protocol is here.
Web servers often handle a lot of other things, but that is the basics. If you want a small program that also runs a web server I suggest not re-inventing the wheel. Try incorporating jetty into your server.
ActiveMQ starts an embedded Jetty server, which listens for HTTP connections on that port. You don't need any other server running. It's all done from Java. If you dig down deep enough, you'll find some variety of ServerSocket at the bottom of it all. You can learn all about sockets and listening on ports in the Java Tutorial.
At its simplest level, ActiveMQ is creating a ServerSocket instance within itself and listening for connections using this server socket. A socket is always bound to a port.
One: this port is greater than (or equal to) 1024, so it means a "non root" user can listen on it.
Second: you can bind to ports from dedicated addresses only. This means ActiveMQ may have only opened that port on 127.0.0.1 (localhost). Try and see if you can open that URL from your external interface's IP address: chances are you cannot.
If you are under a Unix system, you can check what program listens on which port by using netstat -ltpn.
The basic system call for binding to a port is listen(2).
I created a game and I want to put it on online. I want to buy a website (I'll probably use goddaddy to buy a domain name and use them as the web host) to use as the server to handle game play. Because I would need a separate server for each game, I would need each game's server to exists on different ports. So this leads to my question, is is possible to access these ports on my future web server? (I wrote the program in Java, so I would assume that I would access the ports from the server side by choosing a port for a ServerSocket, and from the client side by using the IP address from the website and the chosen port for a Socket)
(note: also, I am aware that it may be easier to simply use one port and run the servers on different threads instead, but I am just curious to have my question answered)
thanks a lot,
Ian
Technically it is possible to use different ports, but I don't think that a webhoster like goddaddy will let you run a java process that binds to a special port.
If you mean that you are going to create your own TCP server you obviously can create as many instances of your server and configure them to listen to different ports. But it is year 2011 now. This solution was OK in early 90s.
I'd suggest you to use Restful API that works over HTTP. In this case you can forward calls to server side of each application using URL, e.g.
http://www.lan.com/foo/login?user=u123&password=123456 - log in into application foo
http://www.lan.com/bar/login?user=u123&password=123456 - log in into application bar
In this case you need only one server (the web server) that is listening to socket (port 80).
Your server side implementation could be done using various web techonlogis (php, java, asp.net etc) on your choice.
Yes, that should work. The security manager permits connections to a different port on the same IP address that the applet was loaded from.
You can run a Java server on whatever port you want. Each server will accept incoming requests on one port.
The correct way is simply run on one port and each connection will instantiate a new servlet instance (which happens to run in its own thread) that can then service that request. You usually don't need to run separate ports or worry about concurrency, especially if all the stuff that's shared between connections (e.g. multiple players in one game) is handled through database read/writes.
Your host (GoDaddy) will have to allow you use of those ports, but if they are providing proper hosting (not virtual hosting) and given you your own IP there's no reason why you shouldn't be able to.
Your solution may work theoritically, and I like AlexR's solution. But providers like godaddy doesnt let you run a java server, on ANY port. You will need to find out somebody who does. What I found is the cost goes up from $5/mo to about $20/mo, but you get a much better (read faster) machine. Good wishes, - MS.
Hi I have an application running in tomcat,as well as Weblogic and Websphere
I need to determine which port the application is running and display on the UI
Is there any JAVA api to find that
If your application is already accessed through that port, you can easily get it from HttpServletRequest.
As mentioned by inkredibl the ServletRequest method getServerPort provides this information:
Returns the port number to which the request was sent. It is the value of the part after ":" in the Host header value, if any, or the server port where the client connection was accepted on.
You can't ask a server from the outside for which ports are used by which application. (Ahh, you cam try, but it shouldn't tell). That's obviously a security feature (you could start a port scan, but I guess, that's not exactly what you want...or?)
So the only way out - the application needs to communicate its port number to outer space, either by a simple web page, where the actual port number is desplayed (human-machine-interface) or a separate webservice with a static port number, where a client can request the actual server properties (machine-machine-interface).
(Note: I assumed, the 'UI' is a client application...)