Help to translate from C to java
hello guys,
i am trying to translate a little code from C to java, but i cant..
please help me..
the first part is:
Code :
struct tPacket
{
WORD size;
WORD opcode;
BYTE securityCount;
BYTE securityCRC;
BYTE data[8186];
}; // A genrel Packet
struct tPacket_5000_E
{
WORD size;
WORD opcode;
BYTE securityCount;
BYTE securityCRC;
BYTE flag;
BYTE blowfish[8];
DWORD seedCount;
DWORD seedCRC;
DWORD seedSecurity[5];
};
struct tPacket_5000_10
{
WORD size;
WORD opcode;
BYTE securityCount;
BYTE securityCRC;
BYTE flag;
DWORD challenge[2];
};
and the second part is :
Code :
int rcv = 0;
tPacket Packet;
do
{
recv(Socket, (char *)Packet, sizeof(Packet), 0);
if (rcv > 0)
{
if (Packet.opcode == 0x5000 && Packet.size == 0x25)
std::cout << "First Packet received";
else if (Packet.opcode == 0x5000 && Packet.size == 0x09)
std::cout << "Second Packet received";
else if (Packet.opcode != 0x5000)
{
pritnf("%.4X %.4X %.2X %.2X", Packet.size, Packet.opcode, Packet.securityCount, Packet.securityCRC);
for(int i = 0; i < Packet.size; i++)
{
printf("%.2X", Packet.data[i]);
}
}
}
while(rcv != SOCKET_ERROR);
please help me guys :S
thx a lot.
Re: Help to translate from C to java
Hi dear, this could approx be like this-
Code :
public class tPacket
{
public short size;
public short opcode;
public byte securityCount;
public byte securityCRC;
public String data = new String(new char[8186]);
} // A genrel Packet
public class tPacket_5000_10
{
public short size;
public short opcode;
public byte securityCount;
public byte securityCRC;
public byte flag;
public int[] challenge = new int[2];
}
public class tPacket_5000_E
{
public short size;
public short opcode;
public byte securityCount;
public byte securityCRC;
public byte flag;
public String blowfish = new String(new char[8]);
public int seedCount;
public int seedCRC;
public int[] seedSecurity = new int[5];
}
public class GlobalMembersB
{
public static int rcv = 0;
public static tPacket Packet = new tPacket();
do
{
//C++ TO JAVA CONVERTER TODO TASK: There is no Java equivalent to 'sizeof':
recv(Socket, (String)Packet, sizeof(Packet), 0);
if (rcv > 0)
{
if (Packet.opcode == 0x5000 && Packet.size == 0x25)
{
System.out.print("First Packet received");
}
else if (Packet.opcode == 0x5000 && Packet.size == 0x09)
{
System.out.print("Second Packet received");
}
else if (Packet.opcode != 0x5000)
{
pritnf("%.4X %.4X %.2X %.2X", Packet.size, Packet.opcode, Packet.securityCount, Packet.securityCRC);
for(int i = 0; i < Packet.size; i++)
{
System.out.printf("%.2X", Packet.data.charAt(i));
}
}
}
while(rcv != SOCKET_ERROR);
}
Re: Help to translate from C to java
ok.. thx a lot.
but let me tell u,
i am trying, to make a connection, with a server socket..
when it is done, i need to receive an packet, and response to it..
how do u think i can do it?
if it not exist in JAVA?
please help me.. i realy need it,
i am pressed to make it working..