java - 将整数二维数组从 java 客户端传递到 python 服务器
问题描述
我正在尝试使用套接字将整数数组从 Java 客户端传递到 Python 服务器。我尝试使用 Java 传递数组ObjectOutputStream
并获得响应。但是 Python 服务器将响应记录如下;
Connected by ('192.168.1.2', 55258)
b'\xac\xed\x00\x05'
b'ur\x00\x02[IM\xba`&v\xea\xb2\xa5\x02\x00\x00'
b'xp\x00\x00\x01\x00\x00\x00\x00\x01\x00\x00\....
这些是\x01\x00\
内存位置吗?我该如何解决这个问题?
服务器(Python):
HOST = 'localhost'
PORT = 1234
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((HOST, PORT))
s.listen()
conn, addr = s.accept()
with conn:
print('Connected by', addr)
while True:
data = conn.recv(1024)
if data:
print(data)
else:
break
s.close()
客户端(Java):
//Variabels
static Socket s;
static DataOutputStream dos;
static PrintWriter pw;
int [] input_row_data = {1, 60, 402, 8, 2, 2};
try
{
s = new Socket("localhost",1234);
pw = new PrintWriter(s.getOutputStream());
ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
out.writeObject(input_row_data);
pw.flush();
pw.close();
s.close();
}catch(IOException e)
{
e.printStackTrace();
}
解决方案
推荐阅读
- c++ - 如何按照 Google C++ 样式指南连接字符串文字?
- graph - n 个节点的最小共同祖先的 AQL
- asynchronous - Flutter:从 Future 中获取价值的正确方法
- r - 饼图以及 infoBox() shinyApp 数据框错误
- django - 在 Django 中创建自定义页面查看计数器
- winapi - Windows - 从代码打开文件并等待它关闭
- database-connection - SQL 查询执行是 TTFB 的一部分吗?
- mysql - 删除重复的表单选择结果
- javascript - 将输入转换为文本而不影响表格列
- django - 图片上传不适用于 DRF 和 React