示例#1
0
  @Override
  public SctpChannel accept()
      throws IOException, SctpException, InvalidKeyException, NoSuchAlgorithmException {
    logger.setLevel(Level.INFO);

    DatagramPacket receivePacket = new DatagramPacket(buffer, buffer.length);
    SctpPacket packet = null;
    while (true) {
      serverSocket.receive(receivePacket);
      try {
        packet = new SctpPacket(buffer, 0, receivePacket.getLength());
      } catch (SctpException e) {
        logger.log(Level.WARNING, e.getMessage());
        continue;
      }

      logger.log(Level.INFO, "receive new packet");

      InetSocketAddress address =
          new InetSocketAddress(receivePacket.getAddress(), receivePacket.getPort());
      packet.apply(address, this);

      Association association = pendingAssociations.get(address);
      if (association != null && association.getState() == State.ESTABLISHED) {
        return new SctpChannel(association);
      }
    }
  }
示例#2
0
 @Override
 public void send(SctpPacket packet, InetSocketAddress address) throws IOException {
   byte[] data = packet.getBytes();
   serverSocket.send(new DatagramPacket(data, data.length, address));
 }