Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Help to translate from C to java

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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:
    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 :
    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.
    Last edited by helloworld922; March 27th, 2010 at 03:59 PM.


  2. #2
    Junior Member
    Join Date
    Mar 2010
    Location
    Home-Ujjain /Job-Mumbai
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help to translate from C to java

    Hi dear, this could approx be like this-

    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);
    }
    Programmer

  3. #3
    Junior Member
    Join Date
    Mar 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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..

Similar Threads

  1. Translate Java Code Into English
    By drkossa in forum Java Theory & Questions
    Replies: 4
    Last Post: November 27th, 2009, 02:52 PM