Package java.net

Examples of java.net.DatagramPacket


    while (!this.eagleDNS.isShutdown()) {

      try {

        byte[] in = new byte[udpLength];
        DatagramPacket indp = new DatagramPacket(in, in.length);

        indp.setLength(in.length);
        socket.receive(indp);

        log.debug("UDP connection from " + indp.getSocketAddress());

        if(!this.eagleDNS.isShutdown()){

          this.eagleDNS.getUdpThreadPool().execute(new UDPConnection(eagleDNS, socket, indp));
        }
View Full Code Here


        }
      } catch (IOException e) {
        response = this.eagleDNS.formerrMessage(inDataPacket.getData());
      }

      DatagramPacket outdp = new DatagramPacket(response, response.length, inDataPacket.getAddress(), inDataPacket.getPort());

      outdp.setData(response);
      outdp.setLength(response.length);
      outdp.setAddress(inDataPacket.getAddress());
      outdp.setPort(inDataPacket.getPort());

      try {
        socket.send(outdp);

      } catch (IOException e) {
View Full Code Here

   * @exception IOException communication error (after getRetryCount()
   * retries)
   */
  public RadiusPacket communicate(RadiusPacket request, int port)
  throws IOException, RadiusException {
    DatagramPacket packetIn = new DatagramPacket(new byte[RadiusPacket.MAX_PACKET_LENGTH], RadiusPacket.MAX_PACKET_LENGTH);
    DatagramPacket packetOut = makeDatagramPacket(request, port);
   
    DatagramSocket socket = getSocket();
    for (int i = 1; i <= getRetryCount(); i++) {
      try {
        socket.send(packetOut);
View Full Code Here

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    packet.encodeRequestPacket(bos, getSharedSecret());
    byte[] data = bos.toByteArray();
 
    InetAddress address = InetAddress.getByName(getHostName());
    DatagramPacket datagram = new DatagramPacket(data, data.length, address, port);
    return datagram;
  }
View Full Code Here

         // remove only own Proxy-State (last attribute)
         packet.removeLastAttribute(33);

         // re-encode answer packet with authenticator of the original packet
         RadiusPacket answer = new RadiusPacket(packet.getPacketType(), packet.getPacketIdentifier(), packet.getAttributes());
         DatagramPacket datagram = makeDatagramPacket(answer, client.getSharedSecret(), client.getEndpointAddress().getAddress(), client.getEndpointAddress().getPort(), proxyConnection.getPacket());       
       
         // send back using correct socket
         DatagramSocket socket;
         if (proxyConnection.getPort() == getAuthPort())
           socket = getAuthSocket();
View Full Code Here

      // encode new packet (with new authenticator)
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    packet.encodeRequestPacket(bos, serverSecret);
    byte[] data = bos.toByteArray();
    DatagramPacket datagram = new DatagramPacket(data, data.length, serverAddress, serverPort);

        // restore original authenticator
        packet.setAuthenticator(auth);

    // send packet
View Full Code Here

      }

      getLogger().debug9("sending Job Scheduler message: " + msg);

      byte[] commandBytes = msg.getBytes();
      udpSocket.send(new DatagramPacket(commandBytes, commandBytes.length, InetAddress.getByName(_host), _port));
    }
    catch (Exception e) {
      getLogger().warn("could not send message to the Job Scheduler, cause " + e.toString());
    }
    finally {
View Full Code Here

            udpSocket.connect(objInetAddress, intPortNumber);
            if (strT.indexOf("<?xml") == -1) {
              strT = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>" + strT;
            }
            byte[] btyBuffer = strT.getBytes();
            udpSocket.send(new DatagramPacket(btyBuffer, btyBuffer.length, objInetAddress, intPortNumber));
          }
          catch (Exception e) {
            e.printStackTrace();
            throw e;
          }
View Full Code Here

  /**
   * Listens on the passed socket, blocks until stop() is called.
   * @param s socket to listen on
   */
  protected void listen(DatagramSocket s) {
    DatagramPacket packetIn = new DatagramPacket(new byte[RadiusPacket.MAX_PACKET_LENGTH], RadiusPacket.MAX_PACKET_LENGTH);
    while (true) {
      try {
        // receive packet
        try {
          logger.trace("about to call socket.receive()");
          s.receive(packetIn);
          if (logger.isDebugEnabled())
            logger.debug("receive buffer size = " + s.getReceiveBufferSize());
        } catch (SocketException se) {
          if (closing) {
            // end thread
            logger.info("got closing signal - end listen thread");
            return;
          } else {
            // retry s.receive()
            logger.error("SocketException during s.receive() -> retry", se);
            continue;
          }
        }
               
        // check client
        InetSocketAddress localAddress = (InetSocketAddress)s.getLocalSocketAddress();
        InetSocketAddress remoteAddress = new InetSocketAddress(packetIn.getAddress(), packetIn.getPort());       
        String secret = getSharedSecret(remoteAddress);
        if (secret == null) {
          if (logger.isInfoEnabled())
            logger.info("ignoring packet from unknown client " + remoteAddress + " received on local address " + localAddress);
          continue;
        }
       
        // parse packet
        RadiusPacket request = makeRadiusPacket(packetIn, secret);
        if (logger.isInfoEnabled())
          logger.info("received packet from " + remoteAddress + " on local address " + localAddress + ": " + request);

        // handle packet
        logger.trace("about to call RadiusServer.handlePacket()");
        RadiusPacket response = handlePacket(localAddress, remoteAddress, request, secret);
       
        // send response
        if (response != null) {
          if (logger.isInfoEnabled())
            logger.info("send response: " + response);
          DatagramPacket packetOut = makeDatagramPacket(response, secret, remoteAddress.getAddress(), packetIn.getPort(), request);
          s.send(packetOut);
        } else
          logger.info("no response sent");           
      } catch (SocketTimeoutException ste) {
        // this is expected behaviour
View Full Code Here

  throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    packet.encodeResponsePacket(bos, secret, request);
    byte[] data = bos.toByteArray();
 
    DatagramPacket datagram = new DatagramPacket(data, data.length, address, port);
    return datagram;
  }
View Full Code Here

TOP

Related Classes of java.net.DatagramPacket

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.