Note: I have finished converting the DataInputStream and DataOutputStream classes from Java to C# - You can get them here: https://bitbucket.org/CTucker1327/c-datastreams/
This problem is solved.
Okay, this isn’t exactly “Unity Scripting” related and more of a C# relation; However it is be used in my current Unity3D Project, I’ll also state that if you have no experience with programming or you’re worried about getting started because you think it may be difficult and confusing, you should turn back now.
Alright, so basically I’ve been converting the DataInputStream and DataOutputStream classes from Java’s networking package. The reason for this is because I have used java servers for quite awhile and already have a networking structure that I feel is quite capable and I wanted to use it for my game in Unity3D. The only problem lies in the ReadUTF method that rests in the DataInputStream class.
The DataInputStream and DataOutputStream classes in Java use a custom UTF-8 encoding format when writing a string through a network stream, because of this you have to construct it yourself from the data that’s sent, I’m not very experienced with C# and I believe the problem is that I’m using the BinaryReader class incorrectly, or misunderstanding something.
Considering pasting this code here turns into Japanese, I’ll be posting the code on paste-bin.
ReadUTF Method: public String ReadUTF() { int utflen = this.ReadUnsignedShort (); byte[] - Pastebin.com
ReadUnsignedShort method: public int ReadUnsignedShort() { int ch1 = ClientInput.Read(); int ch2 - Pastebin.com
ReadFully Method: public void ReadFully(byte[] b, int off, int len) { if(len < 0) { th - Pastebin.com
For those of you who are curious as to how to String is constructed, here’s a link to the method that builds the string: public int WriteUTF(string str) { int strlen = str.Length; int utflen = - Pastebin.com
The ClientOutput is an instance of BinaryWriter.
Help me out guys, I really need to figure out how to read the strings, I’ve got the C# Client sending them to the server properly, however I can’t get it to read them for some reason?