Can two apps written in different languages communicate? - java

I want to write a mobile app (Android) in Java and have it communicate with a google chrome extension. In order to do this I need to use a socket to send data to the mobile device. This can't be done in JavaScript obviously so I looked into the Native Client compiler which would allow me to use C (Java not supported) to create the socket. The app needs to be written in java. At this point this is all theoretical since I don't know C or Java. I do, however, have some programming experience and am willing to learn these two languages. I don't have any experince at all with sockets.
My question is this, Can I initiate a socket using C and have it send data to an app using Java?

There are many Communication protocols. As implied, protocol suggests a standard interface. Its the standard interface part that guarantees apps written in different languages can communicate. Stated differently, an application written in any "language" that can package up some data, and send it according to the rules of a particular protocol, can successfully send and/or receive data from a program of a different language, but recognizing the same protocol. TCP/IP, for example, is a protocol that allows an application written in one language to send and receive byte data in a way that is recognized by applications written in a different language. It uses well defined and documented common interfaces (eg. IPv4 or IPv6), and is frequently used as a method of communication between applications written in different languages. Routines that use TCP/IP protocols are written in languages such as C, C++, C#, Java and others. These languages (and most other modern languages) have libraries available that simplify and further standardize implementation within applications that talk TCP/IP. Sockets, for example, is a (perhaps the) dominant method used in applications providing internet connectivity. Sockets libraries are available for languages native to both Linux and Windows.

Can two apps written in different languages communicate?
Of course, they can! Just express communication data in some universal exchange format like JSON, YAML or XML and it will be easy readable on almost any platform/language. Binary data is good too, but communicating with it you should know and respect things like alignment and endianness.
NOTE: Javascript can use sockets! You can search term AJAX to know more.

Can I initiate a socket using C and have it send data to an app using Java?
Um, sure. For example, it is unlikely that the Web browser that you are using being written in the same programming language as the Web server you are visiting. That's in part because several languages are usually involved in each side.

Related

Send message to C++/Qt application from outside?

I have a C++/Qt application. I want to talk to it using Java.
I know I can create TCP server/client. What other options do I have?
The problem is that I created TCP server inside the application and it does not work. But works fine when run in standalone mode. So looking for alternatives ways of communication between C++ and Java.
I have a C++/Qt application. I want to talk to it using Java. I know I
can create TCP server/client. What other options do I have?
Basically, what you are looking for is IPC that is supported by both languages properly. You can find several solutions out there:
Java and C++ socket communication.. Obviously, QtNetwork and the socket classes in there could be your friend for this on the Qt side.
http://www.velocityreviews.com/forums/t279534-communication-between-a-c-and-java-program.html
Java Native Interface. You would be able to call C/C++ methods from Java and vice versa, although this would be probably one of the slowest solutions.
Shared Memory (SHM) (Here, QSharedMemory could aid you on the Qt side).
Google Protocol Buffer
Dbus (Here, QtDbus could aid you on the Qt side). This is not necessarily cross-platform a solution, however.
I would personally suggest to use raw socket based low-level solution with the Qt API. This is the most reliable in my opinion, and well-proven technology behind. There is Qt Jambi with Qt style API for the java side, and then of course in C++, you will get the QtNetwork API. This would at least provide you some consistency throughout the projects.

Exchange Object/Class data between Java and C++

I need to pass data between c++ program and a Java GUI that is showing that data. I can put that data in a class but the c++ program could be running on linux(raspberry pie) and java may or may not be on windows. What options do i have?
Kindly help me for same machine processes and also if they are on different machines.
P.S.
On different machines internet connection is available.
You may want to implement some serialization.
I suggest using a simple textual serialization format like JSON (but you might consider also YAML or even XML). There are many JSON libraries available, like jansson (in C), JsonCpp (in C++) and several for Java.
Of course, you need some form of Inter-Process Communication. This can be sockets or pipes. Read e.g. Advanced Linux Programming or some other tutorial. Maybe have some Event Loop (e.g. libev, libevent) or even use JSON-RPC (or perhaps some HTTP server library)
You could use binary serialization like XDR or using libs11n but it is usually not worth the trouble.

Serialised communication between languages

My universities peer to peer communication course uses an in house client/server program for demonstration and (i think) extending it is part of the assessment. The program we use is written in java and uses serialisation for the network communication.
To get a better grip I want to try reimplementing the protocol used in objective c, but googling around I cant find any information on using serialised data between languages. I would like to keep this as simple as possible, ideally be able to drop my replacement server/client onto a network and have it behave.
Edit Didnt actually ask a question there.
Is it possible to communicate between the two serialised formats, How can I make this work without reverse engineering the format java uses.
I would recommend avoiding writing (de)serialization support of java's native serialization in another language.
If you can change the existing Java server and clients, use a more language agnostic serialization format.
Assuming that you are not allowed to make that sort of change, I would define the new protocol, and implement a bridge in Java. The bridge (process) would establish a connection on behalf of each client that connects to it, and translate messages between the Java serialized and language agnostic form. This will provide a good migration strategy.
Java serialization protocol (if it's built-in default Java serialization) is documented, so you won't have to reverse engineer it - check this article and this link. However, if you can, use JSON, XML or XML-RPC; it will be much simpler than creating Java serializer/deserializer in another language.

Efficient file transfer from Java server to multiple C++ clients?

I need to transfer files fast over the Internet from a Java server to C++ clients, where often many clients would need the same files. I was looking at say transferTo() in Java which sounds like it would be a decently optimized function to send files. However, I'm not sure when I use transferTo() how to best receive that in C++ (i.e. is it just a raw data transfer, how do I determine when the file is over on the client side, etc.). I need this to work on both Windows and Linux. Also, other than transferTo(), would there be some way to be more efficient, especially by taking advantage of the fact that many clients will usually need the same files? I'm not sure how to do say multicast etc. Also, I'm using application-level security rather than a VPN, and on the Java server, encrypting with AES and using MAC digital signing, so I'm also looking for a cross-platform library recommendation to deal with the crypto on the C++ side with minimal pain.
I'm very proficient in C++ but have no previous experience with network programming, so please consider than in any suggestions.
Thanks.
An embedded webserver? http-transfers are efficient enough for you?
The simplest embeddable Java webserver I remember seeing is http://acme.com/java/software/Acme.Serve.Serve.html. We use embedded Jetty 6 in production at work, but that takes more elbow grease.
If your clients doesn't know where to find your webserver in the first place, consider announcing using Zeroconf. http://jmdns.sourceforge.net/
For scalability reasons, Thorbjørns suggestion of using http seems like a very good idea as it would allow you to easily set up http proxies for caching, use standard load balancing tools and so forth.
If you are looking to transfer more than just a blob of data, you might want to have a look at googles protocol buffers. They allow for very easy and fast encoding/decoding on the java and c++ end.
Consider chunking the file and sending via UDP datagram. C++ can re-compile as it receives it. Have you considered implementing/embedding an existing P2P protocol implementation?
If you need effecient transfer to many clients then your bottleneck is the server.
For this please look at the bit-torrent protocol as it distributes the transfer between the clients.

Can Java apps integrate with VB apps?

I am not sure exactly what I am asking....The guys that do the software development for the company I work for write everything in VB. I am currently the Web developer for this company and I specialize in Flex apps. I am thinking about expanding into their area. But I do not want to do VB, I don't mean to bash on VB but the coding syntax is not for me. So I am wondering if Java can integrate with VB? Also not sure if it matters but I think everything they do is procedural, and I will be doing OOP.
Thanks.
There are lots of integration opportunities, but before examining them, if I were you I would re-examine the question itself.
It should be exceptional to introduce a new language into an established project. The desires or aesthetic preference or skillset of a single developer is not a good enough justification to do so. Introducing a new language into a project should be a strategic decision for the project, not a backhanded one.
If you do choose to expand the core languages used to develop the system,
COM interop
is possible with JACOB. I believe IBM has a bridge as well.(Check alphaworks)
Java-.NET bridging
is possible via JNBridge and other bridges. This makes sense only if VB.NET is in use.
SOAP, XML document exchange, REST
suitable over a services boundary. It requires TCP or HTTP or some network protocol.
common data stores
can serve as a rendezvous point. Both Java and VB can read and update data in SQL Server, Oracle, MSMQ, MQSeries, and so on. Even a filesystem can be an integration point.
Think of data format as related to, but ideally independent of, the integration mechanism. What I mean is: You can use an XML document for integration, whether it is stored in a database, or sent over a REST interface, or stored in a filesystem, or put/get on a queue. You can use a comma-separated file over any of those mechanisms as well.
Potentially they could expose a service layer via soap or something simpler? Also you could always work against the same database with different languages however unless most of the logic is in stored procedures (not necessarily recommending this approach) then you end up with repeated code.
Not really. Java uses CORBA for interop, and VB uses COM for interop. You may be able to make a bridge using JNI, but I understand that can be quite the pain.
I haven't done this by I believe you have the following options:
Use the Java-COM bridge, as VB uses COM. This library was already mentioned here several times
If you are using VB.net, you probably use hessian, As it has both Java and C# implementations.
You could bridge the two using a C/C++ adapter to map JNI calls with COM. But that would be horrible. I hope there is a better solution, but my understanding is that it is pretty hard to integrate .NET code and Java as both vendors (Sun and Microsoft) don't have any incentive to streamline that kind of development.

Categories