I want to send String from C# to Jave
I do it in C# in 2 side like this
Sender: C#
NetworkStream ns1 = _client2.GetStream();
byte[] b = { (byte)2 };//this is the command that sent from client to Server
ns1.Write(b, 0, 1);
string data = "222222222";
byte[] b2 = _AC.GetBytes(data);
ns1.Write(b2, 0, b2.Length);
Reciever C#
Byte[] b = new byte[10];
ns.Read(b, 0, b.Length);
string Data = _AE.GetString(b);
while (ns.DataAvailable)
{
b = new byte[10];
ns.Read(b, 0, b.Length);
Data += _AE.GetString(b);
}
I do some coding with no luck in Java …. like this..
byte b = is.readByte();
byte[] buff= new byte[8];
is.read(buff,0,10);
I receive inside buff[50,50,50,50,50,50,50,50,50];
…..then how to change it to string in java …..
Any help would be great ….thanks
50 is the numeric ASCII value of the character “2”. Just take each element of
buffand apply a cast of char to it:(char) buff[0],(char) buff[1]etc.