How can I use C # to fetch Java data from a socket?
I want to send data BigInteger
to a socket and my friend wants to receive data.
I am using Java, but my friend is using C #.
String str = "Hello";
BigInteger big = new BigInteger(str.getBytes);
byteToBeSent[] = big.toByteArray();
I am sending this byte array ( byteToBeSent[]
) over a socket. And my friend wants to receive "Hello".
How is this possible?
a source to share
From Java, send your string using String.getBytes (encoding) and provide an encoding that matches how your friend will read it (like UTF-8).
This will translate your string into a stream of bytes, which will translate to the end of C # due to the fact that you both agree on the encoding mechanism.
I'm not sure what your BigInteger mechanism is doing, but I don't believe it will be portable and doesn't handle meaningful strings.
a source to share
You will need a custom BigInteger class for C # .
But parsing "Hello" as a big integrator won't work. I want to send text, it is better to use Navaars method.
a source to share
At the end of C #, you can use System.Text.Encoding.ASCII.GetString (bytesToConvert []) to convert the resulting byte array to a string.
I thought it was some Java idiot for converting a string to a byte array. It will correctly convert the string to ASCII bytes, and since the length of the BigInteger is arbitrary, the length of the string shouldn't be an issue.
a source to share