I have a Java program that uses ServerSocket to listen for connections on my local port. I want to put this online so other people can also run the client and connect. I just want the host to literally run my .java program in an infinite loop. All the cloud hosting sites talk about Apache, Maven, and databases but that all goes over my head. How can I get them to run my .java file in an infinite loop so people worldwide can connect to the server socket?
You can have your own server at home, you only need to contract to your Internet Service Provider and they will give you a publc IP and your server will be public.
Another option is to contract a cloud server like Amazon EC2, they have an option and give you a basic server free for a year.
https://aws.amazon.com/es/ec2/
Or you can contract a VPS virtual private server, it's a dedicated server online for you, it's like EC2 but without virtual machines
Related
I would like to connect to an REST Web Service through a VPN. Is there a way in Java to establish an pptp, l2tp ipsec connection to the VPN gateway an tunnel the HTTP request, without using the Operation System functions? This is important because I will connected to several rest services from a servlet. This Services could be behind different VPNs and I do not want to connect the network of the server with this VPNs.
Do anyone know about an API for that?
If you want to connect to a server behind a private VPN, from the outside, nothing you can do on you app can/will allow you to do connect. Unless you launch a VPN client and programmatically connect your network, to that VPN server, your java app will just sit there waiting for a socket on http connect.
Your question is technically incorrect (not from the SO point of view).
Look for a VPN client library that will pop up a dialog and take username/pwd.
A VPN has the purpose of connecting networks. If you want to reach another system via a VPN you will have to establish a network connection.
a Java API for all of this protocols will be (nearly) impossible, since VPN is handled by OS drivers and not on the application level (where java has its place) in most cases.
If you don't want to have your physical server being connected with those VPNs, you could perhaps set up a virtual system with virtualbox or vmware (or others) which handles all those connections and use it as a proxy. But this is no java issue than.
Here is a simple Java API that allows you to use Nord. I've made several bash scripts that also allow me to start, end and cycle NordIKE-VPN sessions. I have not used this yet, but I am intending on repurposing it for use with Android.
https://github.com/yaniferhaoui/NordVPN-Public-Java-API
I made application with java using socket. My computer is the server and my phone(android ) is the client. Only what i trying to do is to forward String from phone to client PC.
Everything works fine when i configure my router and open the port i using. i don't want every time when costumer will install my application will need to open port in the router.
I thought about using remote server that will run my server code. but i didn't find server that can do that . i don't want to make my pc a server for all costumers.
How does all the chats companies do it without open port?
You must look into UPnP. This is what /most/ if not /all/ torrent clients use to allow foreign connections, without forwarding ports. How chat clients do it is a different scenario. They use hacks such as firewall hole-punching using UDP (with an external server) http://www.h-online.com/security/features/How-Skype-Co-get-round-firewalls-747197.html see this link for details on UDP hole punching.
Also see this article http://www.codeproject.com/Articles/13285/Using-UPnP-for-Programmatic-Port-Forwardings-and-N for usage of UPnP. But this is in C++, but I think you will understand.
EDIT: http://4thline.org/projects/cling/ I found this. I think it can help you.
You had to open port probably because of your routers firewall :). If you already opened let us say port 9090 then every client app (android phone) will be able to connect to it :). Of course if somebody wants to install server on their own pc they would problably forward some ports and disable some firewalls. If you want server with no special requriements lookup VPS'es. :)
I have developed a Java server using Eclipse that accepts TCP socket connection from android client, performs some computations, and returns the result to the android phone using this socket. I tried it on Wi-Fi.
I want now to move the Java server to the cloud - basically amazon EC2. Is this possible? I am just using a simple tcp socket connection. I have checked and couldn't find an example but came across "elastic beanstalk". Any help is appreciated, maybe a link or tutorial with such an example.
can i convert my java project to .war and use it or can i install eclipse on the cloud and run it as i do locally?
It is definitely possible. And you don't have to convert your project to a .war, unless you want to.
All you have to do is:
Pick the Amazon Image (AMI) you want to use - Amazon Linux is a good place to start, but there are plenty of other options, including Ubuntu and Windows.
Set up a security group - you need to set an incoming rule for your server's port number. It is pretty easy to do this from the Amazon web-based console.
Start a machine and assign it to the security group you created. Again, this is easily accomplished from the amazon web console.
Once the machine is up, log in (using ssh for Linux or Remote Desktop for windows) and install your server.
A few things to remember:
Since you are now running on a public server, sooner or later your server will be attacked. EVERYONE gets attacked. If all you are opening is your single application port, make sure it is secured.
An Amazon server has a private and public IP. Your client application will connect to the public IP.
Servers can fail, and new servers get new public IPs! You need to prepare for this. Either make the IP in the client configurable, or look into something like Amazon Elastic IPs or dynamic DNS.
I have a client/server applciation that communicates through JNDI/RMI/IIOP using, on client side, some Glassfish client code (NOT packaged as a Glassfish client) and on server side a Glassfish instance.
I have some Glassfish multimode scripts that I use to make sure the domains I create on any machines are totally identical and correctly configured.
Using that script on local network, I have already made sure I could access a remote Glassfish server instance from client code on my machine (that was quite a reasonable guess, however I tend to test all things I'm not totally sure of).
Next step is to have that client/server application working over (I should instead say "through") internet : with my client code in my company LAN (in other words on my machine) and my server code on an Amazon VM running my Glassfish server. For some reasons, the remote Glassfish is running on a Windows VM.
Obviously (as I ask that question, you can safely guess the through internet test is NOT working. And you're right.
So, to have more guesses, I started SmartSniffer both on my machine and on server.
On my machine, I can only see one TCP packet going to that server instance (and nothing coming back).
On server instance, I can see one packet entering (the client query) and one packet exiting (the server answer). That server answer looks like this :
[4/4/2012 11:47:13 AM:917]
GIOP.......(................NameService....._is_a...................NEO................ª.......(IDL:omg.org/SendingContext/CodeBase:1.0............n........172.27.63.145.Ô2....¯«Ë........e...........................
...................
... ...........&...............(IDL:omg.org/CosNaming/NamingContext:1.0.
That 172.27.63.145 address is my IP in local network.
[4/4/2012 11:47:13 AM:917]
GIOP.......2............NEO................0.......(IDL:omg.org/SendingContext/CodeBase:1.0............ô........46.137.114.###.'5....¯«Ë........d...........................
...................
... ...........&...........!...|...............$...
...f............10.241.42.###.'6.#........g..............g........default...................g...............+IDL:omg.org/CosNaming/NamingContextExt:1.0.............¢........10.241.42.208.'5...M¯«Ë....
...d... S1AS-ORB............RootPOA....
TNameService............................... ...................
... ...........&......
That 46.137.114.### is external one of my Amazon VM, and 10.241.42.### is its internal IP in amazon magical virtual server.
So it seems server is answering, no ?
But that answer never finds its way to my machine in my network.
So ... how can I check where it get lost ? Seems likepacket sniffer has done its job, but what can I do now ?
NOTE This question is a clarification of "How to Connect a glassfish client to glassfish server over NATs?"
Perhaps stupid question, but is your Amazon EC2 instance is configured with all required ports open for your communication protocol to work? You could see configured open ports in security group your instance assigned to in AWS console, under EC2->Security Groups.
I just set up a MySQL server on my PC for testing Java with JDBC.
At the moment "localhost" works perfectly as hostname for my applications, when running them on the same system.
However what would be the hostname for my MySQL server for applications that are running on different computers? Something like "my_ip:port" would work? I was thinking of writing an applet, which I could upload on a web server and try to connect to my database here. Is it possible to achieve that?
Something like "my_ip:port" would work?
If the MySQL instance has bound to your public interface, and if your firewall allows it, yes. If you connect to the 'net via a router that does NAT (for instance, a combined DSL modem and wireless router allowing you to connect multiple computers), you'll have to set up forwarding rules in the router to tell it which of the local machines to forward requests to.
You don't have to use an IP address. Your machine will also probably have a host name of some kind (either one you've assigned or, if you connect through an ISP, more likely one they've assigned). That would work too.
I was thinking of writing an applet, which I could upload on a web server and try to connect to my database here. Is it possible to achieve that?
With a signed Java applet, yes; otherwise, no. That's because the security sandbox that Java applets run in doesn't let them access servers other than the one they were loaded from (the web server).
A much better approach is to have your client-side code (Java applet, or just DHTML+Ajax stuff) talk to server-side code on the web server, which in turn talks to your DB. That way, the DB is never directly exposed to the outside world, and you don't have to do things like signed applets.
You can always use the ip address of the server running mysql as the hostname or its fully qualified domain name.
That should work, but you also should consider port-forwarding through your firewall.
Go here to get your IP: http://www.whatsmyip.org/
The port is the port mysql is setup on.