Client Server Java app - java

I developed a client server based java networking Instant Messaging app. The client program is needed to be run on the client computer whereas the server program is on server computer. This works in my local wi-fi network(Home network). But i want this one to deploy on internet using some servers and so,so that my friend who is in another city can run the client program from there. Would it be possible for me to do this? I tried to learn heroku techniques for java but its hard for me to understand.

i want this one to deploy on internet using some servers and so,so
that my friend who is in another city can run the client program from
there
You can !
I have two ways:
1: You register static ip, so you can configure you client and
server program to connect each other.
2: Client get current public ip of server(by using some free services:
email, instant messessing,..), server will auto get current public ip and auto update it's ip(by using some free services), client auto update public ip of server. You can get current public ip of server by whatismyip

Related

How to put Java ServerSocket online?

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

Java server on OpenShift

At the moment i have an android client app which connects to my java server through socket - serversocket. It sends and receive strings. The java server is connected to a mysql database (actually mariadb) using the jdbc driver.
I succeed to create a jbossas application and upload the code of the java server to openshift, but i didn't find any detailed tutorial on how do i connect to this new uploaded server from my socket client (This one (RMI or socket connection to Java Program on OpenShift) gives some tips but i'm still stucked).
More on this, how do i know that my server runs just fine on openshift and how do i control de calls to the database after i connect it (found this: $ rhc app create MyApp jbossas-7
$ rhc cartridge add mysql-5.5 -a MyApp), using org.mariadb.jdbc.Driver and java.sql is still working ?
Any small guide or tip is highly appreciated. I'm new to these things so please don't be too heavy on comments.
You can only make connections to your OpenShift server on http/https or ws/wss ports. If you want to connect to your java application and pull data from it from an android device, I would suggest using a RESTful api or a servlet, etc.
I had similar problem: My app server originally was running as a ServerSocket listener, and any clients/devices connect to it directly via Socket binding.
To deploy it into OpenShift, my previous initial solution was to change its host:port configuration by following the suggestion as described in this link [Socket connection to Java Program on OpenShift]. It worked nice as far as my app server was successfully up and running. But it did not work well with the port forwarding approach in order to accept remote requests.
So for the final solution, I modified the app server by wrapping my original code with a RESTful webservice around it, and deploy it as a web service.

Problems with router configuration for sever client

I'm working on a java project for some time now, the project contain a server and a program that connect to the server.
until 2 weeks ago, every thing worked fine, i could connect to the server from my own network ( that run the server) and from other network (WAN) as well.
2 weeks ago i provider network and got a different router from them, so as i did before i entered its settings and
opened the port for my program ( with port forwarding and all this..) how ever, it doesn't work well as it was before.
if I'm using the ip (from whatsMyIp) and put it in the client, i can enter to the server from other networks how ever I cant enter to it from my own computer that run the server.
if I'm using the ip (from ipconfig), i can enter the server from my own computer however other networks cant connect to
my server.
(as i told before, all worked fine before i changed my router)
hope you can help me.. thanks
If you can access the server from outside your network using your public IP but not from a computer in your local network (using the same public IP) then check your router settings (firewall or port forwarding). There's probably a setting there allowing port forwarding only from your public interface and not from your private int.

Why are there other apps trying to connect to my Azure port?

I'm new in Azure and I'm having some troubles here. I'm implementing a JAVA server application on my Azure VM. It's listening for requests from an Android client. I have tested the java server app on my machine and it works great. When I run the same java server application on my Azure VM it looks like there are other apps trying to connect through the same port. I have checked and every single time I change the port it happens again (it happens when the firewall is down, when I don't shut down the firewall it doesn't even receive a single request).
I have a message showing when there is a connection through the port 4567 and couple seconds after I start my server app it shows that there is a connection from a similar IP than the one I have assigned and I haven't yet run my android app. I configured the endpoints, and I even shut down the firewall and it is giving the same issue. The client app and the server app are working perfectly if I run the server on my local machine. Help would be really appreciated, thanks in advance.
What you might be seeing is the way Azure manages/monitors public Endpoints. When you expose a public endpoint for your VM Azure will behind the scenes periodically test that port to make sure it is up and listening for traffic. This is part of the way Azure manages load balancing for public Endpoints. Because of this, if you watch connections to your the local port on your VM to which the public endpoint is mapped, you will see connections from Azure internal IPs.

Amazon EC2 server TCP Socket Connection

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.

Categories