i am sending data from netty to an c# application in unity 3d game engine where it reads packet id and executes different methods depending on packet id ( inside a thread ),the packet id that the BinaryReader Reads is Wrong and i cant understand why
here is the classes custombuffer,datainputstream,dataoutputstream : https://docs.google.com/document/d/1LmW8fzGFFnkgqV_kS-TnBi7XvVYTC4Q4kHWJT60UF00/edit?usp=sharing
you dont have to read them carefully i posted them so you get an idea of what they are
this is the login method
public void SendLogin(string username,string password)
{
Debug.Log ("Sending username and password");
CustomBuffer buffer = new CustomBuffer (ClientOutput);
buffer.WriteUTF (username);
buffer.WriteUTF (password);
buffer.SendBuffer ();
}
here is the server handler for the sendLogin
public PacketEncoder sendLogin(boolean value, Account account,byte opcode) {
ChannelBuffer buffer = new DynamicChannelBuffer(2);
ChannelBufferOutputStream out = new ChannelBufferOutputStream(buffer);
try {
out.writeInt(0);
out.writeBoolean(value);
System.out.println("sendig login back packet 0");
if(value) {
System.out.println("value true sending username");
out.writeUTF(account.getUsername());
}
else if(!value) {
System.out.println("value false sending opcode : "+ String.valueOf( (int)opcode));
out.writeByte(opcode);
}
Send(out.buffer());
out.close();
} catch(IOException e) {
e.printStackTrace();
}
return this;
}
HERE ITS WORKING PROPERLY! below is the problem
this is the netty method that sends back information after character creation request
public PacketEncoder SendCharacterCreationResult(boolean exists,boolean success) {
ChannelBuffer buffer = new DynamicChannelBuffer(2);
ChannelBufferOutputStream out = new ChannelBufferOutputStream(buffer);
try {
out.writeInt(2);
out.writeBoolean(exists);
out.writeBoolean(success);
//debug console
System.out.println(" ");
System.out.println("Sending Character Creation Result packet : 2");
System.out.println("exists : " + String.valueOf(exists));
System.out.println("success : " + String.valueOf(success));
Send(out.buffer());
out.close();
} catch(IOException e)
{
e.printStackTrace();
}
return this;
}
this is the packet handler from c#
void InputLoop()
{
while(Client.Connected)
{
int packetID = ClientInput.ReadInt();
Debug.Log("packedID : " + packetID);
switch(packetID)
{
case 0: //Login
PacketsIn.Login();
break;
case 1://Character Request Response
PacketsIn.CharacterRequest();
break;
case 2: //Character Creation Response
PacketsIn.CharacterCreate();
break;
}
}
}
after login which its handled perfectrly server sends character creation result with packet id 2 and when it comes to the client first it runs the packetsIn.Login() (which is the packetid of 0) and the writeInt(2) from the SendCharacterCreationResult
is readed from the method below where byte opcode = ClientInput.ReadByte ();
that equals (2) i tried it like this int opcode = clientInput.ReadInt(); it gave the same result. if i confused u tell me to add full files in text
this is the function of case 0 in the inputloop (which is running in a thread)
public void Login()
{
bool success = ClientInput.ReadBoolean ();
if(success)
{
string username = ClientInput.ReadUTF();
Debug.Log("Successfuly Logged In. " + username);
MasterClient.singleton.ChangeScene(4);
}
byte opcode = ClientInput.ReadByte ();
//GameObject.Find ("MessageLogsText").GetComponent<UILabel> ().text
Debug.Log( GetLoginMessage (opcode) );
}
private string GetLoginMessage(byte opcode)
{
switch(opcode)
{
case 0:
return "Invalid Usarename Or Password";
case 1:
return "Account Is Already Logged In";
case 2:
return "test";
default:
return "Invalid opcode Sent From Server";
}
}
then packet id becomes 513 and i cant understand why