Java Server for Android Application - java

I need to write a server in java that will store integers that are used as stats for my android app. My app has an SQLite database that is already setup that would be useful if I could just pass those contents to the server. I need to do this so that in my multiplayer feature, a player's app will contact the server to know what level their opponent is. (This is not real time). So far I only have a TCP server that opens a client and server socket. Other than that I am not positive what I need to do to make it possible for the server to do what I need. Anyone have suggestions or good tutorials to help me with my problem?
Thanks.

One thing you need to keep track of:
Your SQLite DB has to be used as a player session, until the player logs in as another user. To do this, you have to have one instance of the current logged in player. If you prefer other methods, here's a good list.
I don't think you would need a TCP connection to view the stats, instead implement a REST API in PHP or any other language for back-end that would save, update and look up for a particular player. This is a recommended method. If you are familiar with PHP, this tutorial will give you an idea and full details of what I mean.

Indeed, building a server has many methods. For example, You can use either socket programming or app-server. If you are familiar with web programming, jsp/php/asp.net, you can communicate between your app and server with HTTP requset, which is easy to do.
To be more specific, someone (neme:abc,password:pwd) logging in with your mutiplayer app, when he or she leaves, send the data to server with HTTP request. Then when he or she logging in with other device, you can get the data from status and continues to play. Of course, you can save the data in local with SharedPrefence in Android, too.
By the way, the apache HTTPClient is recommend when using http connection with server.

Related

Server for arduino

I am trying to set up a server to receive data from arduinos and display the data on a website. I can handle the arduino client side but...
I purchased a website through hostgator and am completely lost on how to use a service such as that to get what I want. Using an arduino as a server, or using a private or lab server is not an option.
I could do it in java, but the service would won’t support java unless I spend more money for a dedicated server and I’m not willing to do that.
Any help would be greatly appreciated!
Are you set on using an Arduino?
If your aim is to stream data directly to a web server, there are plenty of better options out there with built in wifi and all the libraries you could dream of.
I suggest a nodeMCU, or if you are set on an arduino, you will need an ethernet shield.

Mqtt Check if a client is online or offline

I am using mqtt and mosquito broker to build a simple instant chat for an android platform. Now I wanted to implement a condition where any client can check if another client is online.
I know about Last will and testament but I wanted a user to be detected offline only wen the application is inactive or the user is not currently using the app.
I actually dnt need any code, buh wanted an idea as to how to implement this and I would be much grateful.
You can do this without relying on MQTT internals which is much easier in my view. With this approach, you have much more control over what is going on:
The client can periodically send a message within another topic to inform the server of its availability. In case the server does not receive that message after a specified amount of time, it can assumed that it is offline.
The client can also send another message if the user logs out and inform the server a well.
If you insist on using MQTT internal structure, you may find this question useful:
How to Find Connected MQTT Client Details

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.

Making a client-server chat - running into issues with connecting client to client

I am trying to learn how to make a multiple-client chatting program. Im following the Oracle tutorial on Custom Networking, but its not really what I am looking for. So far, I have no code of my own to share, all of it is copied from the Oracle tutorial and I think pasting it here would be a copyright infringement(??).
link at: http://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html+
client code link: http://docs.oracle.com/javase/tutorial/displayCode.html?code=http://docs.oracle.com/javase/tutorial/networking/sockets/examples/KnockKnockClient.java
anyway, I have the server-client working where the server tells knock knock jokes, the client reads and prints, then the user replies and so on. how would i start to edit it to have the client talk to the other clients directly?
im sorry, i have no background with networking at all. if anyone can direct me to a informative source better suited to my goals i would appreciate it.
as in the Knock-Knock example, each client connects to the server, but they not mutually directly connected.
There is a solution to make a forwarding sever :Arrange each client an id, and clients use id to identify their talking partners.
To do this, you have to modify the client to server data format from a plain string to a tuple like (String,Id). And, when the server receive the data, it parses out the id, get the corresponding client socket and then write the data.
The required level of complexity just went up a notch as your going to need some sort of "interprocess communications" infrastructure to allow client to client communication (possibly via sockets marshalled by the server?)

Need clarification of LAN application concept

Recently i developed a simple chat application in java using sockets. It was working fine. But now i want to make an application which can communicate over the Local Area Networks like IPMSG. The features will be
message sending.
file sending.
voice chat.
group chat.
encryption/decryption on demand.
These were the basic features to be included.
Now the confusion i am facing over here is
The application is an peer to peer application in which one user can do anything what other users can do.
There is no centralized server and there in no client. Every node acts as a server and client both.
So the application has to be peer to peer. But when i googled it then i am getting samples like client-server only and when i talk to my peers regarding this then also they suggest me the client-server model but there is no justification for why client-server and why not peer to peer. Am i right in this case ? Can anyone please guide me in this case because once i start development on any of these concept i cannot revert back due to time shortage. Your suggestions are most welcome.
I think the main reason a server-client relation is advised, is to make it easier for logging, or make a large chatroom for everyone (like IRC). If there is a login required, the server would also verify the login details. So without a server in between, phishing attacks would become more difficult to deal with.
I don't see why a P2P chat wouldn't work, though. If I recall correctly, Skype is doing that. I always love decentralizing. Good luck with your project. :)
You might want to check out the Zeroconf standard and packages that use it like Avahi (linux FOSS) or Bonjour (Apple & Windows open-source but not GPL). Zeroconf allows for configuration and detection of network services without user interaction or a central configuration server.
I end up using a client server model modified to support to P2P networking. When a node comes into the network it broadcasts its presence and the other nodes are continuously listening for new nodes. Each node will have their own list for the connected nodes in the network. In case of new node coming into the network they will update their own lists. I am using UDP for all most all the operations except file transfer as it needs to be in TCP.

Categories

Resources