Are sockets programming language independent?
Can I keep the server written in Java and client written in C?
Absolutely. Otherwise it would be pretty hard to write a web browser and a web server, just as an example...
Of course, the data you communicate over the socket may be easier to read with one language than another - for example if you use Java's DataOutputStream
, that's going to be easier to manage with Java at the other end to read the data. But you still could read that data, as the format is well documented.
If you put absolutely platform-specific data across the network though, that makes things harder - it would be tricky to use an object serialized with Java's ObjectOutputStream
from a non-Java platform, for example.
But at the raw sockets level, there's no concept of which programming language the source happened to be written in.
A TCP Socket communicates via a binary stream of data. Many languages have features that sit a top this stack to make communication easier, but at its simplest its just binary data.
If you want to communicate between two different languages just avoid any custom serialization of the languages and stick with something simple like passing simple strings back and forth.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With