Since I'm a newbie to Java web server, I don't know where to begin to create a server in Java to reply from Android devices request( A WEB SERVER NOT AN ACTUAL SITE).
Which technology should I use and which document should i read?. I have searched on the Internet about Java but i found out many technologies and i don't know which one i can use.
Spring MVC,JSF,JSP,Struts,Servlet..............
Hope this question clear enough for you to reply. Thank you
It doesn't matter what be process android devices requests on server side. In this case main idea is http communication - client sends request, server process this request and sends response to client, and you can use any technology on server side - java, php etc.
If you prefer java I can suggest you try servlets, it is simplest technology of those you mentioned above.
Related
I am trying to write a simple client-server application in Java using HTTP request/response. I would like the client to be a desktop program which sends (posts) a request to a server. The server is a web page which will be hosted on Apache Tomcat server. The server must be able to read the information and display it on the browser and must be able to respond to the client with a status code 200. I am using eclipse and Apache tomcat server. I have so far tried various resources, but all I could find is a client which could request response from an already existing web server. Could someone please give me an example or some insight on how to make the client request the our own server which runs on the local machine.
Good question, though in your case, I won't recommend you implement a simple HTTP request/response approach as you will end up implementing a timer, heartbeat or Comet. You might wanna try javax or jetty WebSocket API. All you need is to create three parts:
a websocket.server
a websocket.client (desktop application)
a javascript websocket client (browser agent)
Your server and both clients will become full-duplex via onMessage and send events.
Here's an example which I believe is a bit relevant one.
https://dzone.com/articles/sample-java-web-socket-client
I had before a project where i need to push data(websocket) to the client i used spring and atmosphere framework(an abstract of websocket in java). But finally i think actually websocket app in java are not enough good since i used nodejs&socket.io for an another project. It was so easy and a great experience to code an push data api.
So now i am thinking about an architecture and i want to share with you to know if its a good practices.
I have my server spring, client and nodejs/socket.io. I want to use nodejs just to store de socket and push event.
So imagine the server has to push data to specific users i will call a service in nodejs and he will push it.
So the nodejs API will just redirect requests to a user, nothing more.
Is that a good practice ?
Thanks for your idea
I would advice you decouple java application server and nodejs (socket server) and communicate using a middleware (messaging system..)
Let's say your java application is running on http://abc.com:1234 and socket.io on http://abc.com:5678. Then when the page is opened you can subscribe of the socket server.
Once you have some data to push, put it on middleware. SocketIO server will pick it up from there and pushes to all the browser client subscribed.
I think this might be a very stupid question.
I have 2 servers that are going to communicate with each other via HTTPS using XML packets.
My question is this, there is no webpage just a Java application. How would I get my Java app to run when it hears an XML packet from the other server? Are the messages to be sent via POST?
I know about HTTP protocols but my knowledge goes as far as webservers to sending the webpage to browsers, server to server communication w/o a webpage is baffling me. Can anyone point me to the right direction or better still to some codes that I might be able to look at.
Thank you.
You can use HttpClient in your server applications so that they become clients to each other. Then maybe simply implement REST services for the 'clients' to call.
I would suggest trying this out firstly using HTTP before trying it in HTTPS.
Of course there are other technologies you could try E.g JMS or SOAP.
I am building a android clients - single server application, and want to use JSON objects for communication. Will have some simple database on the server. what would be a good scheme for server side implementation. Here are my options:
Socket programming - then can I still use HttpClient on the android client?
HttpServer - I heard it is not working well with android, and how do you do multithreading on server side?
any other recommendation would be helpful. thanks
There is some interesting discussion over at this SO question that may provide some useful info: How to call a SOAP web service on Android
I'm working on a server client base "Desktop Application". And what I want to do is this,
Client application sending some request code to server through internet(oh yes, these connections must be secured). and when server application gets this code it will again do some work and gather some data.
And then server application will return those data again to the client application.
As I am new in this, I need to know, what kind of tools to use?
Is eclipse good for that?
Where can I find good examples for writing client?
Where can I find examples for connecting client with server side?
I'd recomend checking out apache httpclient it really helps when dealing with web APIs.