首页 > 解决方案 > 将整数二维数组从 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();
            }

标签: javapythonarrayssockets

解决方案


推荐阅读