@Override public void run() { DatagramSocket datagramSocket = null; while (isContinueListen) { try { if (datagramSocket == null) { datagramSocket = new DatagramSocket(null); datagramSocket.setReuseAddress(true); datagramSocket.bind(new InetSocketAddress(listenPort)); datagramSocket.setReceiveBufferSize(512 * 1024); } byte[] buffer = new byte[1024 * 1024]; DatagramPacket udpPacket = new DatagramPacket(buffer, buffer.length); datagramSocket.receive(udpPacket); LPP.put(udpPacket); Logg.e(TAG, "收到2000包"); } catch (Exception e) { e.printStackTrace(); Logg.e(TAG, "收到2000包 error"); continue; } } if (datagramSocket != null) { datagramSocket.close(); datagramSocket = null; } }
@Override public void run() { while (isContinueListen) { DatagramPacket udpPacket = null; try { Logg.i(TAG, "准备从LPP列表中取出一个UDP数据报"); udpPacket = LPP.take(); Logg.i(TAG, "从LPP列表中取出了一个UDP数据报"); } catch (InterruptedException e) { e.printStackTrace(); Logg.e(TAG, "run error"); continue; } boolean isScreenLocked = ((ClassWorkActivity) mContext).isScreenLocked(); if (!isScreenLocked) continue; int packetLen = udpPacket.getLength(); byte[] packetData = udpPacket.getData(); int operationType = myConvertByteArrToInt_bigend(packetData, 0); System.out.println("操作类型为" + operationType); // handDraw(packetData); switch (operationType) { case OPERATION_TYPE_HANDDRAW: handDraw(packetData); break; case OPERATION_TYPE_ERASE: eraseArea(packetData); break; case OPERATION_TYPE_LINE: drawLine(packetData); break; case OPERATION_TYPE_RECTANGLE: drawRectangle(packetData); break; case OPERATION_TYPE_ELLIPSE: drawEllipse(packetData); break; case OPERATION_TYPE_TEXT: drawText(packetData); break; case OPERATION_TYPE_PAGE: changePage(packetData); clearCanvas(); break; case OPERATION_TYPE_CLEARCANVAS: clearCanvas(); break; case OPERATION_TYPE_UNDO: undo(); break; case OPERATION_TYPE_REDO: redo(); break; case OPERATION_TYPE_MOVECANVAS: moveCanvas(packetData); break; } } // end of while } // end of run