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

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

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

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

客户机:java

  1. BufferedReader in = new BufferedReader(new InputStreamReader(soc.getInputStream())); //object
  2. String[] Recive=null;
  3. int length=Integer.parseInt(in.readLine());
  4. System.out.println("Length : "+ length ); // 4
  5. for (int i = 0; i < length; i++) {
  6. System.out.println("recive Packets");
  7. Recive[i] =in.readLine();
  8. System.out.println("From Server: "+Recive[i]);
  9. System.out.println("----------------------------------------------------");
  10. Thread.sleep(1000);
  11. }

java输出:

  1. Length : 400000000000000101100000000000101000000000000000100000001000000000000001011000000000001100000000000000001000000100000000000000010110000000000011100000000000000010000001100000000000000101100000000001000000000000000000100000100
  2. From Server: NULL

暂无答案!

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

相关问题