Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can sockets accessed in different programming languages communicate?

Tags:

java

c

sockets

Are sockets programming language independent?

Can I keep the server written in Java and client written in C?

like image 589
Nageswaran Avatar asked Feb 24 '11 07:02

Nageswaran


2 Answers

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.

like image 181
Jon Skeet Avatar answered Nov 15 '22 15:11

Jon Skeet


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.

like image 44
developresource Avatar answered Nov 15 '22 15:11

developresource