1

I have made a very simple command chat java base application.

Although the Project is consist of one being functioning as the Server and the other one being the Client which sends Sockets and receive Sockets from the Server.

But the Server is not a Servlet or any other kind, it's just a simple plain java class that function as a server via ServerSocket...

If it can be hosted online (cloud preferably) how will I know the new hostname for the Client to use??? Will the port change to???

Server class

public class ServerDoor {
    public static void main(String args[]) throws IOException {
        final int portNumber = 81;
        ServerSocket serverSocket = new ServerSocket(portNumber);
        while (true) {...}
    }
}

Client Side

public static void main(String args[]) throws IOException {
    final String host = "localhost"; // the host name!
    final int portNumber = 81;
    System.out.println("Creating socket to '" + host + "' on port " + portNumber);

    while (true) {...}
}
Miko Chu
  • 319
  • 3
  • 14
  • Those are details of how exactly you go about hosting it. For example, if you register a domain name for the server you may specify that name in your client. You might examine the static methods of the [InetAddress](http://docs.oracle.com/javase/8/docs/api/index.html) class to get some ideas. – President James K. Polk Jan 25 '16 at 21:42
  • Is there any cloud that supports java? Specially not being a servlet but being a simple java class. I mean like being able to upload java class to the cloud and is that even supported? – Miko Chu Jan 25 '16 at 21:50
  • Cloud services such as Amazon EC2 and Google Compute Engine give you a virtual machine where you can run any software, including Java. – yole Jan 25 '16 at 21:55
  • @yole The JVM is supported and does not require me to configure it? And I can also upload raw java classes? How can a java class run on the web??? Please correct me if I am wrong or fix my misconception. – Miko Chu Jan 25 '16 at 21:57

1 Answers1

1

You can host your server in Windows Azure or Amazon EC2 or other cloud hosting companies. The hostname that your client needs to connect to is the IP address or DNS name of your server. Maybe change your client to accept the hostname and port from command line arguments instead of hard-coding localhost.

The port that your server binds to will need to be the same one as the one that your client connects to. Consider using command line arguments for this as well.

The Java sockets tutorial is pretty useful as well.

The easiest way to get started is to create a VM from the cloud hosting company. You can use SSH to remote into your cloud VM in order to run commands. If you're not familiar with command line applications, you should look into it a little bit. You will have to know how to run your Java program from the command line.

Once you have a VM, use SCP or another copy utility to copy your Server Java jar or .class files onto your cloud VM. You can then run your Server program from the cloud VM. Make sure that your cloud VM allows connections from the port that you will be using. You can open or close ports for your VM from your cloud hosting VM settings.

Once the Server program is running in your cloud VM, you can connect to the VM's hostname and port. The hostname will be the domain name of the VM instance you created. You will likely have to give it a unique name when you create the VM. It will also probably be the same name you use to SSH into the machine.

Community
  • 1
  • 1
tmajest
  • 350
  • 1
  • 5
  • I can upload raw java class to the cloud??? I have so many question because right now I can't try the cloud, how will I know the name of my DNS server??? Is it like the domain name when uploading a website? – Miko Chu Jan 25 '16 at 22:03