0

I would need a little help with converting my python code into Java. I haven't written anything related to this function in Java yet, because I don't know how struct.pack works in java for this particular case.

def get_garena_token(user,password,region):
if region == 'cis':
    GARENA_AUTH_SERVER = 'Honsng_cs.mmoauth.garena.com'
else:
    GARENA_AUTH_SERVER = 'hon.auth.garenanow.com'
PORT = 8005
ip_region = 'XX'.encode('utf8')

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((GARENA_AUTH_SERVER, PORT))

user = user.encode('utf8')
password = password.encode('utf8')

data = struct.pack('<IHHB16s33s5s',0x3b,0x0101,0x80,0,user,password,ip_region)
s.send(data)
data = s.recv(42)
s.close()
parsed = struct.unpack('<IB32sBI',data)
return parsed[2]

Thank you.

  • At least tell us what `struct.pack` in Python does. And while you're at it, you'll probably see some things that you can port to Java. – mthmulders Jul 23 '13 at 13:18
  • 2
    This question might be of use: http://stackoverflow.com/questions/3209898/java-equivalent-of-pythons-struct-pack –  Jul 23 '13 at 13:18
  • struct.pack module performs conversions between Python values and C structs represented as Python strings. This can be used in handling binary data stored in files or from network connections, among other sources. It uses Format Strings as compact descriptions of the layout of the C structs and the intended conversion to/from Python values. –  Jul 23 '13 at 13:39
  • 1
    This is just an idea to go around the problem rather than a real solution. Try using jython. write your code in jython and then get java bytecodes of it. then you can use .class file in your java project – Moh Zah Jul 23 '13 at 13:45
  • Still can't get this to work. –  Jul 23 '13 at 16:00

0 Answers0