Java int 到 python int
我有一个 Java 服务器,它将接受来自 python 套接字的连接,并返回 python 脚本应连接到的新端口的 int 值。然而,python 脚本返回的“字符串”显然无法转换。
这是 python 片段:
s._PORT = int(s._sock.recv(1024))
print s._PORT
以及 java 端:
int mPort = 1592;
sock.getOutPutStream().write(IOS.getBytes(mPort++));
// IOS being a utility class that I wrote just to make byte conversions easier
谢谢 ~伊顿
public static byte[]
getBytes(Object obj)
throws java.io.IOException
{
ByteArrayOutputStream bos= new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(obj);
oos.flush();
oos.close();
bos.close();
byte[] data = bos.toByteArray();
return data;
}
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 ObjectOutputStream(bos);
oos.writeObject(obj);
oos.flush();
oos.close();
bos.close();
byte[] data = bos.toByteArray();
return data;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)