Can I access localhost from multiple virtual clients with Glassfish? - java

I'm learning to program java enterprise edition applications (web applications). to test the correctness of my coding i need multiple clients to access my project simultaneously (i.e test concurency), the projects are deployed with glassfish and accessed on the localhost, i tried to use multiple web-browsers unfortunatly the result interpreted tells me that i am only accessing my project withe the same client, so this is my question:
Can I access localhost from multiple virtual clients with Glassfish?
Do you have a name for tools to simulate virtual clients from the same machine to test my coding?
Edit: what i need is to access my project with some sort of browser client for multiple concurrent users, to test something like a board game or a chat application.

Not with localhost; but you need to find the ip address of your server. Then using servers ip address you can test as 127.12.13.45:8080/app
So using ip address in place of localhost; you can test your app from different client machines.
Apart from this; you can also use some of the testing tools which allows you to simulate multiple clients from the same machine.

Have you considered Apache JMeter? It can (among many other things) simulate multiple concurrent users.

Related

How can I have multiple localhosts in a machine?

Suppose, I want to test two server applications and one client application such that if one of the servers fail, the client can still be connected to the second server without the interruption of a task.
In order to do that, I need two localhost addresses so that each server can expose one endpoint to to the incoming clients.
How can I achieve that in a laptop?
Some suggests using Virtual Machines with Internal Networking. But, my PC can't take the memory load of two virtual machines running simultaneously.
Any suggestion?
Run the servers on different ports.
While using servers like Tomcat, Jboss, etc. You can make separate instances and bind separate ports using configuration (mostly xml ) files.

Access Application using same ip within office network

I've deployed one application developed using Java-Struts on one of my client's office. Application is web-based - So we hosted it on one the machine available in client's office - using static ip. The application runs fine(well I had couple of issues to deal with honestly). But when we were testing the application within client's environment - we came across odd issue.
If client needs to access the application inside their network - they need to use local ip address, something like this -
http://192.168.1.12:8080/CTS
Outside the network - they need to use following url -
http://99.99.999.999:8080/CTS
How I can make sure client does not have to use 2 different urls to access this application?
I went through few forums and got to know about host mapping and NAT forwarding, etc. I'm not a networking expert, So I really need some guidance of how to achieve this with right method.
Thank you very much in advance.
For security reason the intranet IP(http://192.168.1.12:8080/CTS) is not exposed publicly.Have to check with the network team of Client whether the IP is publicly exposed if not then map local IP with domain/Static IP and that should be exposed publicly.If it is publicly exposed then within the network too the client can access intranet IP/domain.

Assign IP to a Java application

I've just developed a Java application that crawls a lot of websites.
My dedicated server details: Linux, CentOS, zPanel.
I have 1 IP on my dedicated server for many domains and I've just bought an additional IP to assign it to the .jar or related domain only.
How can I do this operation?
You can't. You assign an addresses to the network interface, not the application.

How can I communicate with an object on a remote machine?

I know my IP address, and that of my friend.
How can I transfer objects/files between the two machines?
I am an advanced Java programmer, but have never worked with networks before.
EDIT:
I am now using an API called jnmp2p ( http://code.google.com/p/jnmp2p/ ).
It works fine when I use internal IPs, but fails when I give the external ones.
How do I connect to a computer that isn't on my private network?
If you looking for communication between two java applications and do not want to meddle with the low level networking details, then you can use following two approaches, depending on the type of applications you are dealing with.
If both the application (on two machines) are java standalone applications, then RMI is the best bet. Check out the basics from these links (1,2)
If your application (receiving files/objects) is a web application then its you can write the Servlet on the serve side and then write a client application to send files/objects(binary) to server. Commons FileUpload is very popular library for this purpose.
Author of jnmp2p here. I don't maintain the library any more because I've moved onto other things. However I had some comments.
Peer to peer communication with IPs outside your private network is a hard problem. This is because stateful NATs and firewalls on both ends have become common-place, which prevent you from establishing connections between machines directly.
For example skype uses a rendezvous service where both machines start outbound connections to a third machine and communicate via that. Aside from setting up additional infrastructure that any peer to peer solution is going to be limited to subnets within your NAT, so solutions like JNMP2P or RMI (with gross modifications) are going to be your best bet.

Is it possible to access the different ports on a web server?

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.

Categories