How can i host java udp program for my android application? - java

i am developing an android application in which the server side execution is done using a simple java udp program.i want to know how i can host this application because i need a static ip server to run the java program.can i run my java program in a server.is it possible if yes how?

You'll have to write a listener in some language (PHP, Java, Etc.). As for a static ip address, you can also look at a dynamic ip redirection service like no-ip;
http://www.no-ip.com/services/managed_dns/free_dynamic_dns.html
You can use a personal machine thats always online, or you can try to use a shared hosting plan that allows you to have a listening port open. A web service will likely be easier to work with than having some custom UDP/TCP connection.

Related

Can i host my ServerSocket or Java file somewhere on the web?

Heyy guys. I'm writing a chat application in java, works pretty well. But can i somehow host my Server file or the Serversocket on the web? I want to make it so my friends from other pcs can use the client and connect to the server file which is hosted on the web. Is that possible? Can i host the File/socket online?
When you run a java application that opens a ServerSocket, it opens a port on your local machine and starts listening for incoming connections. What you do with those connections is up to the implementation of the java code that you write.
The "web" is much less foreign than you are making it out to be. Your own computer can be on the web that you're talking about and people can connect to your chat service. Or you can choose to host it on something like an AWS server.
The following approach is assuming you are behind a pretty standard NAT config.
Once you run your java application, you need to make sure other computers can see you, either inside your LAN or outside on the internet. You want to start testing from as close to your computer as possible, then start expanding outward.
First you need to make sure that your computer's firewall is actually allowing connections on the port that your java application is listening on.
Opening ports in the Windows Firewall
Setting up and opening ports in Linux
Now computers on your LAN will be able to connect to your java program. Now you need to go one layer out, and port forward your router. This is much less standard so I can't help you too much, but Google can.
At this point, anyone on this internet, knowing your external ip and what port your java application is listening, can connect to your service.
If you chose to host this on an third party hosting service, you'll need to go through similar steps, but there may be slight differences that you can either ask about, or again Google is a great resource.

Uniquely connect an android application to a java applet on pc

I want to connect my android application to an applet which is running on my pc on Google chrome on Wi-fi.. where my phone works as a wi-fi hotspot and pc as the connected device. I want the connection to work uniquely as I want commands to be passed from my application to the specific applet, on the execution of which my applet does specific tasks. Please tell me the APIs which I can look in both Java and Android or the technology I have to use to make it work..
You need to use any program, such as wamp server, to make your computer to be a localserver. It will install PHP 5, MySQL and Apache. In other hand, you will also need a little bit of knowledge in Php language to create you own web services.
Another thing you need to be aware is that to handle you connection between server and device (and by this I mean which IP you are going to use) you will have a little headache; but first things first..break your problem in little parts thus will be easier to solve them.
I recommend this tutorial.
I think the simple way to connect these two softwares is using UDP.
It is fast, it is easy to program but it is generally unreliable according to TCP. But it is already local network. I dont think that is a case you need to take care in your local wifi network.
So take a look at this tutorial http://tutorials.jenkov.com/java-networking/udp-datagram-sockets.html
There are other ways like https://www.alljoyn.org/. It has more functinality but more complicated.
You must install Server on your PC(Apache httpd or apache tomcat or other based on your interest). A server listens to request from clients. When your mobile is connected to your pc(doesn't matter wire or wireless), you can make a request to an url(say, localhost:8080/welcome) from your app.
Create an applet and connect it with your web application(in the server) using java.net.URL and java.net.URLConnection.
On performing some operation on the client, call the url of the server application and forward the response to the applet.

UDP packet capturing on a servlet application running at GAE

I have a code running in router that sends UDP packets(using Sendto() function and a string of data) to a particular server whose IP address and port number I will mention in my code.
I want to deploy a server application that could receive a UDP packet and store its information on server or somewhere else not sure right now.
I have decided to use Google app Engine for hosting my server side code which most probably will be having something like recvfrom() function to receive string.
So how and by using what API's can I start developing my server side code.
Google App Engine has a Preview release of a Socket API, but it does not let you create listening sockets. See Limitations and restrictions section at https://developers.google.com/appengine/docs/python/sockets/
You cannot create a listen socket; you can only create outbound sockets.
You can use Google Compute Engine to run any reasonable software on Google's cloud platform, including programs that receive UDP datagrams. You must always pay for Compute Engine instances.
According to the newest edition of App Engine Socket docs for Java, if you're using java 8 runtime you should be able to use java sockets without limitations:
Applications in the Java 8 runtime default to using native Java
sockets with no restrictions: Google recommends that you keep this
default.
That means that it should be possible to use java.net.DatagramSocket or java.nio.channels.DatagramChannel freely to work with UDP.

Java Sockets : Application with both server and client on same machine

I am developing an application to send, receive or update files using Socket, ServerSocket class in Java.
There is one single application which is both server as well as client. I need to get the IP addresses of all other applications running on the same Local Area Network.
How can this be done?
You should use broadcast for this.
For more details take a look here: http://docs.oracle.com/javase/tutorial/networking/datagrams/broadcasting.html

how to launch java socket-server on remote server

OK, I'm new to server-client applications, and i need some basic information, so forgive me if my question is not clear...
I want to make a chat application that would function like this:
Client A sends information to server, server sends the same information to client B, and vice versa... Think of it as of a simple chat program.
All communication is done through sockets, so i would have a server socket application, and a client socket application... I want my client application to be on my PCs and server application to be on a remote server ( it would be hosted on some free hosting websites).
My question is how do I start that server application on that remote server?
Thanks in advance!
If you are just trying to make a chat client, I don't think you would need an intermediate server. Just connect two machines using server and client sockets
SERVER:
ServerSocketChannel serverSocket;
serverSocket = ServerSocketChannel.open();
serverSocket.socket().bind()
serverSocket.socket().accept()
CLIENT:
SocketChannel clientSocket = SocketChannel.open();
clientSocket.connect();
Of course you would have to use the bind and connect functions properly. Read up on their API's
The remote server can be started manually. (If you do not have access to remote server or if you are hosting your server on some third party infrastructure, then they might have a way to do it.)
To be able to start it remotely via some program, you again need a server on the remote machine that listens to this kind of requests.
Usually, you want an application that is running all the time at your hosting provider (like a web server or perhaps inetd) to start (or embed) your application. The details will be determined by what your hosting provider provides.
If you're using plain sockets, you should look for some remote server with SSH login. You're able to start your application on the shell then, sth like:
java -jar yourapp.jar
Free hosting websites are rather targeting customers that want to host their website. In my opinion that is not the best choice for hosting a socket application.
For developing purposes, I'd stick with the local machine for the beginning. Running/testing server/client connections on the same machine is much easier as you don't have to work on two different machines, copy code, etc.
This tutorial is relatively short, but fully covers basics of Java networking. And it is right about simple chat.

Categories

Resources