Page 1 of 1

how to let applications communicate

Posted: Mon Dec 04, 2006 4:19 am
by raghavan20
let me say there is an appliation A and another application B
and there is another appliation or software component C

A and B make requests to C for some data or to perform some operation and C performs the requested action.

Now how can A and B communicate to C and how C will communicate back to them

1. do you use Web Services?
2. cURL?
or somethingelse


Please let me know the available ways and the best way to let different applications talk?
One case can be taken like A is developed in PHP and C is in PHP as well
Another case would be A in PHP but C in desktop Java.

Posted: Mon Dec 04, 2006 4:55 am
by Chris Corbyn
Usually you'd just acess what you need in a database which can be remotely accessed if needed. Do you need to get the other app to perform actions? For that you'll need some sort of API or if it's simple enough use cURL. I'd be half tempted to write a service with the socket functions and communicate by using plain-text commands over a fsockopen() handle.

Posted: Mon Dec 04, 2006 5:02 am
by raghavan20
typical examples would be catalogue management, identity management.

there will be tools in the sense software components or applications will be developed to handle those services.

All other applications who want services related to catalogue and identity management, should query them instead of directly accessing databases and implementing scattered logic everywhere.

i am basically trying to centralize operations that would be required in different applications and now my doubt is all about how to make applications contact with applications offering those services.

Posted: Mon Dec 04, 2006 9:23 am
by Chris Corbyn
raghavan20 wrote:typical examples would be catalogue management, identity management.

there will be tools in the sense software components or applications will be developed to handle those services.

All other applications who want services related to catalogue and identity management, should query them instead of directly accessing databases and implementing scattered logic everywhere.

i am basically trying to centralize operations that would be required in different applications and now my doubt is all about how to make applications contact with applications offering those services.
I'm pretty sure that wouldn't be too difficult to develop a service for it, which runs on a dedicated port ;)

Posted: Mon Dec 04, 2006 9:28 am
by raghavan20
d11wtq wrote:
I'm pretty sure that wouldn't be too difficult to develop a service for it, which runs on a dedicated port ;)
chris, i am not sure how to run it as a service. can you show me some example tutorial for me to understand? Thanks

Posted: Mon Dec 04, 2006 10:46 am
by Maugrim_The_Reaper
Do a google search for "REST web services tutorial" and be inundated with examples...;).

A basic web service is simply a set of URIs which each return a separate contextual response. For example, if I implemented a web service for news. I would have URI's pointing to:

news/add
news/delete
news/get

news/add would accept a request containing the news item you want to add. news/delete would accept a request with a news ID to delete. news/get would accept a request containing data to be used for selecting news items. This isn't so hard once you get over the fact the client interface is not sourced from the web service - you create it separately at another location. Also a web service rarely responds with HTML, usually it will return a data format such as XML, or even JSON.

For example, you might create a news item using a PHP app connecting to your service. The App sends the following POST request:

news/add?apikey=XXXX&text=<urlencoded news text>

apikey is a simple identifier - all requests could contain it to restrict access to registered users with a valid API Key. Not the most secure bit of coding (it can be intercepted) but its commonplace and done all the time. An SSL enabled URI would be better.

The response from the server?

Code: Select all

<response>
    <status>success</status>
    <news>
        <id>1</id>
        <text>
            <![CDATA[I'm the posted news item in a CDATA sections so
            the response XML won't bork when an XML illegal character
            like quotes and amperes are met! My id in the database is held
            within the <id> tags.]]>
        </text>
    </news>
</response>
Using SimpleXML (or the DOM given SimpleXML and CDATA are not on good terms) you can grab the news id and text and do whatever you want with it.

Posted: Mon Dec 04, 2006 11:33 am
by Chris Corbyn
That's not what I was referring to but that's an easier to implement approach :)

I was actually referring to a specialized socket/port service which you could happily telnet to and issue basic plain-text commands to receive plain-text responses.

Like:

C: PRICE id=66498
S: 9.99
C: QUANTITY id=66498
S: 31

XML is a far better approach actually though. It's easy to parse.