Package jnode.protocol.binkp.types

Examples of jnode.protocol.binkp.types.BinkpFrame


      return false;
    }
  }

  protected void sendMessage(Message message, int skip) {
    frames.addLast(new BinkpFrame(BinkpCommand.M_FILE, getString(message,
        skip)));
    logger.l3(String.format("Sending file: %s (%d)",
        message.getMessageName(), message.getMessageLength()));
    try {
      message.getInputStream().skip(skip);
View Full Code Here


              Thread.sleep(100);
            } catch (InterruptedException e) {
            }
          } else {
            try {
              BinkpFrame frame = frames.removeFirst();
              try {
                socket.getOutputStream()
                    .write(frame.getBytes());
                socket.getOutputStream().flush();
                logger.l5("Frame sent: " + frame);
              } catch (IOException e) {
                logger.l2("IOException: "
                    + e.getLocalizedMessage());
                break;
              }
            } catch (NoSuchElementException ignore) {
            }
          }
        }
        logger.l3("(sync) processOutputObserver exits");
        closed = true;
        return;
      }
    };
    ThreadPool.execute(processOutputObserver);

    try {
      greet();
      while (!closed) {
        if (!isConnected()) {
          try {
            Thread.sleep(100); // let's proccess to write messages;
          } catch (InterruptedException ignore) {
          }
          continue;
        }
        try {
          int[] head = new int[2];
          for (int i = 0; i < 2; i++) {
            head[i] = readOrDie(socket.getInputStream());
          }
          int len = ((head[0] & 0xff) << 8 | (head[1] & 0xff)) & 0x7FFF;
          int remaining = len;
          ByteBuffer data = ByteBuffer.allocate(len);
          boolean command = (head[0] & 0x80) > 0;
          while (remaining > 0) {
            byte[] buf = readOrDie(socket.getInputStream(),
                remaining);
            remaining -= buf.length;
            data.put(buf);
          }
          data.flip();
          BinkpFrame frame;
          if (command) {
            BinkpCommand cmd = BinkpProtocolTools.getCommand(data
                .get());
            if (data.get(len - 1) == 0) {
              len--;
            }
            byte[] ndata = new byte[len - 1];
            data.get(ndata);
            frame = new BinkpFrame(cmd, new String(ndata));
          } else {
            frame = new BinkpFrame(data.array());
          }
          logger.l5("Frame received: " + frame);
          proccessFrame(frame);
        } catch (IOException e) {
          error("IOException");
View Full Code Here

              Thread.sleep(100);
            } catch (InterruptedException e) {
            }
          } else {
            try {
              BinkpFrame frame = frames.removeFirst();
              try {
                process.getOutputStream().write(
                    frame.getBytes());
                process.getOutputStream().flush();
                logger.l5("Frame sent: " + frame);
              } catch (IOException e) {
                logger.l2("IOException: "
                    + e.getLocalizedMessage());
                break;
              }
            } catch (NoSuchElementException ignore) {
              logger.l3("NoSuchElement exception");
            }
          }
        }
        logger.l3("PIPE processOutputObserver exits");
        closed = true;
        return;
      }
    };
    ThreadPool.execute(processOutputObserver);
    try {
      greet();
      while (!closed) {
        if (!isConnected()) {
          try {
            Thread.sleep(100); // let's proccess to write messages;
          } catch (InterruptedException ignore) {
          }
          continue;
        }
        int[] head = new int[2];
        for (int i = 0; i < 2; i++) {
          head[i] = readOrDie(process.getInputStream());
        }
        int len = ((head[0] & 0xff) << 8 | (head[1] & 0xff)) & 0x7FFF;
        int remaining = len;
        ByteBuffer data = ByteBuffer.allocate(len);
        boolean command = (head[0] & 0x80) > 0;
        while (remaining > 0) {
          byte[] buf = readOrDie(process.getInputStream(), remaining);
          remaining -= buf.length;
          data.put(buf);
        }
        data.flip();
        BinkpFrame frame;
        if (command) {
          BinkpCommand cmd = BinkpProtocolTools
              .getCommand(data.get());
          if (data.get(len - 1) == 0) {
            len--;
          }
          byte[] ndata = new byte[len - 1];
          data.get(ndata);
          frame = new BinkpFrame(cmd, new String(ndata));
        } else {
          frame = new BinkpFrame(data.array());
        }
        logger.l5("Frame received: " + frame);
        proccessFrame(frame);
      }
      finish("Connection closed");
View Full Code Here

                }
              }
              if (key.isWritable()) {
                checkForMessages();
                if (!frames.isEmpty()) {
                  BinkpFrame frame = frames.removeFirst();
                  logger.l5("Frame sent: " + frame
                      + ", next " + frames.size()
                      + " frames, total sent "
                      + total_sent_bytes);
                  write(frame, channel);
                }
              }
              if (!isConnected()) {
                finish("Connect ended");
              }
              if (key.isReadable()) {
                BinkpFrame frame = null;
                ByteBuffer head = ByteBuffer.allocate(2);
                for (int len = 0; len < 2;) {
                  len += readOrDie(head, channel);
                }
                head.flip();
                int header = ((int) head.getShort()) & 0xffff;
                int datalen = header & 0x7fff;
                ByteBuffer data = ByteBuffer.allocate(datalen);
                for (int len = 0; len < datalen;) {
                  len += readOrDie(data, channel);
                }
                data.flip();
                if ((header & 0x8000) >= 0x8000) {
                  // command
                  BinkpCommand cmd = getCommand(data.get());
                  if (datalen > 1) {
                    if (data.get(datalen - 1) == 0) {
                      datalen--;
                    }
                    byte[] buf = new byte[datalen - 1];
                    data.get(buf);
                    frame = new BinkpFrame(cmd, new String(
                        buf));
                  } else {
                    frame = new BinkpFrame(cmd);
                  }
                } else {
                  frame = new BinkpFrame(data.array(),
                      datalen);
                }
                if (frame != null) {
                  logger.l5("Frame received: " + frame);
                  proccessFrame(frame);
View Full Code Here

TOP

Related Classes of jnode.protocol.binkp.types.BinkpFrame

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.