我尝试从服务器(python)发送列表的长度,并使用socket io发送列表项并通过客户端(java)接收它

yzxexxkh  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(174)

我想从服务器python发送列表的长度,然后使用socket io将列表项发送到客户端java readLine() 在java中,让所有接收和存储它的人保持一致,我想把它们分开。服务器:python

commandRecv=['00000000000000101100000000000101000000000000000100000001',
 '00000000000000101100000000000110000000000000000100000010',
 '00000000000000101100000000000111000000000000000100000011',
 '00000000000000101100000000001000000000000000000100000100']
lensend = str(len(commandRecv))  # 4
    lengthOfList = lensend.encode('utf-8') 
    con.send(lengthOfList) # '4'
 for T in commandRecv:
         T=T
         con.send(T.encode('utf-8')) #send  msg
         time.sleep(1)

客户机:java

BufferedReader in = new BufferedReader(new InputStreamReader(soc.getInputStream())); //object 
String[] Recive=null;
int length=Integer.parseInt(in.readLine());
System.out.println("Length : "+ length ); // 4
for (int i = 0; i < length; i++) {

                     System.out.println("recive Packets");
                       Recive[i] =in.readLine(); 
                     System.out.println("From Server:  "+Recive[i]);

                     System.out.println("----------------------------------------------------"); 
                     Thread.sleep(1000);
               }

java输出:

Length : 400000000000000101100000000000101000000000000000100000001000000000000001011000000000001100000000000000001000000100000000000000010110000000000011100000000000000010000001100000000000000101100000000001000000000000000000100000100
From Server: NULL

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题