Ejemplo n.º 1
0
  private byte[] merge(Hashtable msght) {
    int s = msght.size();
    // System.out.println("--------------------s="+s);
    byte[] tmpb = (byte[]) msght.get("" + s + "_" + (s - 1));

    int tmpi = tmpb.length;
    // System.out.println("-----------------1tmpi="+tmpi);
    int len = (s - 1) * MAX_PACKET_LENGTH + tmpi;
    byte[] tmpbuf = new byte[len];
    // System.out.println("-----------------1---");
    System.arraycopy(tmpb, 0, tmpbuf, (s - 1) * MAX_PACKET_LENGTH, tmpi);
    for (int i = 0; i < (s - 1); i++) {
      tmpb = (byte[]) msght.get("" + s + "_" + i);
      System.arraycopy(tmpb, 0, tmpbuf, i * MAX_PACKET_LENGTH, MAX_PACKET_LENGTH);
    }
    return tmpbuf;
  }
Ejemplo n.º 2
0
  private void processMsg(byte[] msgbyte) {
    // 得到主题
    HeaderItem hi = HeaderItem.fetchHeaderItem(msgbyte);
    String strtop = hi.getContentStr();
    // System.out.println("recved header="+strtop);
    if (!msgTopic.isMatch(strtop)) {
      return;
    }
    byte[] tmpbytes = HeaderItem.cutHeaderItem(msgbyte, hi);

    // 得到唯一id
    hi = HeaderItem.fetchHeaderItem(tmpbytes);
    String tmpid = hi.getContentStr();
    // System.out.println("recved id="+tmpid);
    Hashtable tmph = (Hashtable) idMsgBuf.get(tmpid);
    if (tmph == null) {
      tmph = new Hashtable();
      idMsgBuf.put(tmpid, tmph);
    }
    tmpbytes = HeaderItem.cutHeaderItem(tmpbytes, hi);

    // 得到顺序号
    hi = HeaderItem.fetchHeaderItem(tmpbytes);
    tmpbytes = HeaderItem.cutHeaderItem(tmpbytes, hi);
    String strord = hi.getContentStr();
    // System.out.println("recved order id="+strord);
    tmph.put(strord, tmpbytes);
    // System.out.println("recved ="+new String(tmpbytes));
    int d = strord.indexOf('_');
    int pknum = Integer.parseInt(strord.substring(0, d));
    if (tmph.size() == pknum) { // 一个主题的信息收齐,通知顶层
      int s = callBack.size();
      byte[] tmprecv = merge(tmph);
      // System.out.println ("Recving-----"+strtop+"["+tmprecv.length+"]") ;
      if (DEBUG) {
        log("UdpBase Recved<<----[" + strtop + "][" + tmprecv.length + "]");
      }

      for (int k = 0; k < s; k++) {
        ((UDPBaseCallback) callBack.elementAt(k)).OnMsg(this, strtop, tmprecv);
      }

      idMsgBuf.remove(tmpid);
    }
  }