Is it good connect to servlet server from Java, without website? - java

Several days I didn't learned more about Java server development. I can make a small web-server with WebSocket and Servlet, and Hibernate, like a chat or AuthService. But I'm absolute zero in front-end, and just can't use my knowledge. So, when I found how to use my new skill, I realized what I can made Android app instead of website (because I have experience). For example, I have servlets like
/auth/signin
/auth/signup
Is it a good idea make GET and POST query, from Java code, using Retrofit, for example, or not? Given that I dont have a website, only servlet, on
domain:port/auth/
I just don't know how to organize my architecture. It must be simple client-server, client = android.
Questions: Will it be a good decision to use it for client-side? Or if I don't need in website, must I use only socket connection with TCP? And if I can, how my server URL will looks like?(ip:port/ or domain:port/ or domain/)

Related

Creating Server for a mobile multiplayer game

I have to build a server to which I make requests using Unity for a mobile game.
I was advised to stay away from using REST for the server.
I want to be able to, in the client, make GET and POST requests via endpoints like "/players".
My question here is: which programming language and programs do you recommend me to start with to build a server to which clients can communicate with, in this case?
I've been using NodeJS to write servers for my programs and I've found it really good for a couple of reasons:
1) It is easy to understand the syntax (JS) if you've been using UnityScript or C# in the past.
2) There is a free download from the Asset Store that helps you parse and send data from a NodeJS server.

Android Client-Server App & Web Services

I have a website that I'm wanting to create a Java application for, and while I don't have any experience creating android applications I have a decent amount of Java experience and feel like I should be able to complete this task over some time. I'll be making use of the Java.IO package for client-side networking (On the application) and hosting a server using Java. This server application will have access to all of the same databases as the website through JDBC. (I'll be hosting it all on the same server.)
My question is how to go about handling connections on the android platform, currently I verify a dynamically generated salt with the database salt on every page refresh to prevent session theft. I also make sure that the encrypted password and the user-name stored in the session match.
I could theoretically just create a standard server application, using NIO and avoding the whole thread-per-client scenario. The problem is that my website has quite a bit of traffic, and I know the application will too. So I'm running into issues on how to handle it.
If I use a keep-alive TCP connection and store the users basic information in a class data structure (Psuedo example):
class User {
int id;
}
Considering all information will be polled from a database and everything is relative to the id of an account, there's no reason to store any excess data into the User class, correct? Just a quick simple lookup tied to the connection to only get data relavent to yourself.
Should I avoid the use of TCP networking for this? What do you guys think.
On the server side, create REST web services that invoke CRUD operations on the server database, and return the responses to the client as a JSONObject or JSONArray. Android has internal support for JSON parsing, and you can use the Volley library to call the web services. Volley is a pretty abstract, high-level HTTP library that makes it very easy to make REST web service calls. TCP connections are quite low-level and are not generally used in client-server Android apps. See the Transmitting Network Data tutorial for more on this.

Systemdesign: Webserver, API and Database

Currently i have a website offering some product. The webserver sits on the same system as the database and directly accesses it to retrieve the required information for the HTML frontend. Now i think it is good to separate the database from the webserver via an API server. The reason why i want to use an API server is that it might be possible that future applications, other than the website, will need access to the information on the system.
The system which i want should consist of the following components:
A database which will store all the required information.
An API server which will be implemented in Java and should use oauth2 for authorizing user requests. The API server will have the only direct connection to the database.
A webserver.
So basically what i have in mind is that i want to build my website on top of that API server. The user will register/login/... over the website and the website implementation will internally query the API server as a webservice on behalf of the user. The API server would then return the data from the database. That way the HTML frontend is just an application using the API server and will never itself be in direct contact with the database.
I think that this is an often encountered problem for which a good solution exists. I am unsure if this solution is the way to go though. Could you help me out and/or point me in the right direction from here?
Thank you.
As far as I know, it is not advisable to have a separate API server for a couple of reasons: decreasing performance and increasing compexity of a system. So basically you should avoid this type of solution for as long as possible.
You should definitely read M. Fowler: "Enterprise Architecture Patterns" for inspiration.
Returning to your question: have you considered making this API layer as a module (library)?
If I haven't convinced you, try reading Java RMI documentation (http://www.oracle.com/technetwork/java/javase/tech/index-jsp-136424.html)

Connecting Android and java EE server

I am making a game. The client runs in android. It is multiplayer and I want to check as much logic as possible on the server. I am interested how to connect the android client to the pure-java backend. I dont want to deal with the pure sockets as long as it creates a lot of programming overhead. Something like EJB would be perfect, but as long as can see, there is no rmi package in Android or anything. So the only way is connecting it throught Sockets or URL-objects to the REST-service (Could connect with URL to SOAP-based service - but its too complicated to do by hand). Serialization does not work between android and java. What is the best way to connect an Android app in a multiplayer game to the server (better java EE EJB`s or something)? Is there a way except pure XML?
You can use JAX-RS to build a RESTful Webservice, and you can use JSON as the payload. Jersey is a reference implementation, and is a good one. There is JSON support as well.

Java Client-Server communication to register a product

I'm looking for some advice on the simplest way to create some product registration communication. I have a Java desktop application that needs to be re-newed every year. When a user downloads and install this app (through JNLP) they get a limited demo-version. There is code in place on the client to "register" the product and unlock all of the features.
My next step is to build the server-side components. There will be a database with customer ID numbers and other information about the customer. When the user clicks register, some contact information will be sent to the server as well as some product registration ID. The server will check this against the database and then either give the client the o.k. to unlock the features or the user will be informed that the registration id was not valid. This seems like a very standard thing. So what is the standard way to do it?
I have my own VPS and I'm running Tomcat, so I'm really free to implement this any way I choose. I was planning on building some web service, but I have never used REST before.
Use REST; REST is nothing more than using plain HTTP 'better'. Since you are already using HTTP, somehow you are already doing REST like calls and moving these calls to full fledged REST will be easy.
Implementing REST calls is easy. You have two approaches:
Low end: using URLConnection objects on the client, servlets on the server and following some REST conventions on using HTTP methods and 'clean' URLs (see here). Advantage is that you need no 3rd party library and minimize the footprint. Maintenance and evolutions are harder though.
High-end: a framework and specifications like JAX-RS. Using Restlet you can be up in running with a REST server in a couple of hours without having to deploy a servlet container.
Don't use SOAP. The only reason you would want to use SOAP is that you want to contractualise using a WSDL what you are exposing (you can do the same with REST btw, see the Amazon documentation for instance). Trust me, SOAP is way too heavy and confusing for what you are trying to do.

Categories

Resources