Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have searched for some hours now, and can't find an answer. I have a homepage coded in php that needs to frequently send and receive data to a java program.
So far I have done it via POST, but I wonder if it's a better way to do it. I have tried with sockets. But only managed to find tutorials for php client connecting to a java server. But I need the reverse.
All modern languages allow you to send and receive data, no matter from which language is sent or received. Many large applications (such as Facebook API), work with simple methods such as POST, GET, PUT, DELETE, etc., that is a REST API, returning the data in a specific format (JSON, XML, RAW, etc.). This is innecessary if your application is a little piece of code, but you could take this idea and make something simple. So, there is nothing wrong if you are using the POST method, but just in case, I can name you other resources that you could take advantage of.
You can use WebClient.
Also, you can comunicate your PHP code with your Java code using sockets.
TCP sockets: for PHP read this, and this guide for Java.
WebSockets: Java WebSockets for Java and Ratchet for PHP.
Of course, you can use cURL too. For Java you can read this question and connect with php. If your application is very large and complex in the PHP side, I guggest you to use Laravel.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm creating a simple java application made in swing that communicates with a database. Multiple people will be using the application at the same time. As they are able to change things at the same time, if someone for example, adds a new user, and a different person is on that same page, I want the person who did not make the change to be notified that changes were made to the database since they last loaded it.
My lecturer in college advised me that WebSockets would be the way to go to achieve this, however after some reading about WebSockets in Java, it seems it is based to work with web browsers instead of between Java applications.
Can using WebSockets achieve what I am trying? Or, if not, what would be a way to achieve this?
Simple answer is Yes you can achieve what you needed
WebSocket is a communication protocol(#see RFC 6455) & it is not a must to use a Web browser.
You can achieve what you want to do with your app, it is just a matter of writing a custom WebSocket server to facilitate your requirements in your case sending database changes to the other clients(Which is called Server push)
There are several java libraries to get the work done,
netty WebSocket (My favorite)
jWebsocket
Atmosphere
Webbit
Netty WebSocket is a good one to start with and you can find examples in its project to write a custom client and a server
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I were wondering what's the proper way to create a chat/communication software in Java for Android?
I guess it's a Socket (TCP/UDP).
If I do it my own way like using a web calls for PHP with backend scripts why it is not so appropriate way to create a chat? What's the difference between them? Using a calls instead of raw sockets? Does it use more battery or something? I just feel that sometimes it would be more easier to parse a JSON for messages and send data through web calls, but I feel that it's not a proper way to do so and application may have a critical issues like draining a battery or something which will make the project to be discontinued.
I would like to be sure is there any other ways to create a chat, than sockets and do every famous developers use a sockets as primary method for creating a communication software?
The protocol could be Socket or others such as XMPP
If you prefer using Socket, SmartFox might be one of the libraries that you can rely on. Smartfox offers SDK for a number of languages such as C#, Java etc.
Note however, that if you use socket for communication, usually json is NOT used, since most of the times, binary objects are used in the socket-based communications, say for example, SmartFox uses ISFSObject, which wraps all the data into a binary object.
Below posts might be useful for you to get started, though it is not written in java, but essentially the workflows are exactly the same.
Using SmartFox with C# (I) : Installations and 1st handshaking
Using SmartFox with C# (II) : Login and join room
Using SmartFox with C# (III) : Frequently used functions
Apart from the socket and xmpp appraoches, you can also opt to use WebRTC, where there is no such kinds of servers, and peer to peer communication is used. A good tutorial can be found here.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm not sure if the title says what I needed. But that's the best way I can put it.
My requirement: I want to check if a series of engine numbers (of vehicles) are registered with the local transportation authority. They have provide a web-interface for this task, but I can only check for a single engine number at once. Usually I need to check over 200 numbers. So, its a humongous task to check each one individually.
A couple of years ago, I have created a small standalone python script to do this automatically using web scraping, but now I want to do this on a server.
A user gives all the numbers in the text file which they upload/paste the contents in to a text field. Then I'll have to submit the form on the transportation website (using web scraping) for each number and display a final status for all of them.
What I want to know is how to do this on a server? What technologies could be helpful. I'm comfortable with Java & JavaScript. I don't know PHP (But i can learn if needed). I don't have slightest Idea how to do this on server side. Any Ideas and Help is greatly appreciated.
Thanks.
Java has a library called JSoup, which provides a mostly-familiar api that uses css selectors.
And obviously there are built-in functions that can get you the html from a given URL.
Put those together and you've got a server-side scraper
[edit]
Your question, on a re-read, isn't just about scraping -- it's about how to automatically submit an html form from within Java to an external server. This is an interesting question, one I've wondered myself.
this may be an answer: How to send post form with java?
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am exploring various ways that allow Java to connect and communicate with NodeJS. An example of what I am trying to achieve, is for example call Java methods from NodeJS, while allowing the Java method to manipulate Javascript objects. I know the JSObject class is helpful for this purpose. I have also heard so far of Dnode and ZeroMQ. Have you heard of or do you have experience in doing something similar? Would you suggest a way on how this communication Java to NodejS can be done?
I would go with an agnostic implementation.
A rest server on node js, maybe using restify listening for messages
A http client on the java side as httpclient to send messages to node.
this will also make it dead easy to test node implementation with curl and static requests; will enable you to implement authentication later on using any standard mechanism from oauth to basic and will let you change the client and the dispatcher independently later on
also you will be able to put any kind of standard load balancer in between, should you need the node app to scale.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I was wondering if there is a way to pull specific data from a website using java (eclipse). For example, stock information from Yahoo Finances or from Bloomberg. I've looked around and have found some resources, but I haven't been able to get them to work, perhaps I'm missing something or they're outdated. If possible, I also want to avoid downloading any external resources, I've read up on JSoup and will consider it more seriously if all else fails.
Thanks for the help.
The answer is: yes there are many different ways to pull data from websites.
There are essentially 2 alternatives no matter the programming language (Java, .NET, Perl...):
the website has an API: in this case it will be a REST or SOAP API or perhaps a custom one (REST and SOAP probably account for the vast majority). Check out that website's API documentation if any. Also check out Programmable Web for references.
the website doesn't have an API. You then need to do what you call here as screen-scraping. Essentially you will send a series of HTTP GET or HTTP POST requests as your browser would. The server replies with a response which contains HTML code. From there on, you need to "parse" the HTML to extract the information you need. This will require heavy duty XPath (if the content is XML) or regular expressions (if the content is HTML or text).
Look at Apache HTTP Components to get you started.
If all you want is Finance information, Google has a JSON/REST API for that and there's a question on SO that will help you: How can I get stock quotes using Google Finance API?.
Yahoo also has one and there is also already an question on it in SO: Yahoo Finance All Currencies quote API Documentation