开发者

Java int to python int

I have a Java server that will accept a connection from a python socket and return an int of the new port that they python script should connect to. However the 'string" that the python script gets back is blatantly unable to be converted.

Here's the python snippet:

s._PORT = int(s._sock.recv(1024))
print s._PORT

And the java side:

int mPort = 1592;
sock.getOutPutStream().write(IOS.getBytes(mPort++));
// IOS being a utility class that I wrote just to make byte conversions easier

Thanks ~Aedon

public static byte[] 
getBytes(Object obj) 
throws java.io.IOException 
{
    ByteArrayOutputStream bos= new ByteArrayOutputStream(); 
    ObjectOutputStream oos = new ObjectOutputStr开发者_如何学Ceam(bos);
    oos.writeObject(obj); 
    oos.flush(); 
    oos.close(); 
    bos.close(); 
    byte[] data = bos.toByteArray(); 
    return data;
}


sock.getOutPutStream().write(Integer.toString(mPort))

s._PORT = int(s._sock.recv(1024))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜