I have couple questions regarding to overall "sending" philosophy and specific question on what are the options to send various data types and structures over sockets.
Current stage
I have Java application which acts like a server and a client in written C#. I succeeded in connecting and sending integer from C# to Java.
Java
while(true){
try{
int a = input.readInt(); //input is DataInputStream which is initialized in constructor
Console.LogClient("Received {"+a+"}");
}catch(IOException e){
e.printStackTrace();
}
}
C#
TcpClient client = new TcpClient(ip, port);
//Connection established
int value = 11;
System.out.println("Sending: "+value);
byte[] bytes = BitConverter.GetBytes(value);
if (BitConverter.IsLittleEndian)Array.Reverse(bytes);
BinaryWriter a = new BinaryWriter(client.GetStream());
a.Write(bytes);
a.Flush();
Questions
Future plans
I'd like to learn and implement some optimizations later on, like compressions. As i understand it's pure byte[] manipulation? If so, is the BinaryWriter (C#) and DataInputStream/DataOutputStream (Java) the best solutions? Or there might be problems and best is to which to other class which handles this kind of job.
I hope someone could shed some light on this.
Thank you very much!
write(byte[] array)
writes the byte array directly to the underlying stream. This means that flush()
will probably not make a difference here. Actual citation: "Writes a byte array to the underlying stream."I'm just writing with some basic knowledge, so please correct me if I'm completely writing from my arse