Examples of DatagramSocket


Examples of java.net.DatagramSocket

  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);
        socket.receive(packetIn);
        return makeRadiusPacket(packetIn, request);
      } catch (IOException ioex) {
        if (i == getRetryCount()) {
          if (logger.isErrorEnabled()) {
            if (ioex instanceof SocketTimeoutException)
View Full Code Here

Examples of java.net.DatagramSocket

   * @throws SocketException
   */
  protected DatagramSocket getSocket()
  throws SocketException {
    if (socket == null) {
      socket = new DatagramSocket();
      socket.setSoTimeout(getSocketTimeout());
    }
    return socket;
  }
View Full Code Here

Examples of java.net.DatagramSocket

   */
  protected DatagramSocket getProxySocket()
  throws SocketException {
    if (proxySocket == null) {
      if (getListenAddress() == null)
        proxySocket = new DatagramSocket(getProxyPort());
      else
        proxySocket = new DatagramSocket(getProxyPort(), getListenAddress());
      proxySocket.setSoTimeout(getSocketTimeout());     
    }
    return proxySocket;
  }
View Full Code Here

Examples of java.net.DatagramSocket

         // 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();
        else
          socket = getAcctSocket();
         socket.send(datagram);
    }
View Full Code Here

Examples of java.net.DatagramSocket

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

    // send packet
      DatagramSocket proxySocket = getProxySocket();
        proxySocket.send(datagram);       
    }
View Full Code Here

Examples of java.net.DatagramSocket

   */
  public void sendSchedulerRequest(String msg) throws Exception {

    String _host = "";
    int _port = 0;
    DatagramSocket udpSocket = null;
    try {

      _host = sosString.parseToString(arguments, "scheduler_host");
      if (sosString.parseToString(arguments, "scheduler_port").length() > 0)
        _port = Integer.parseInt(sosString.parseToString(arguments, "scheduler_port"));

      if (_host == null || _host.length() == 0)
        throw (new Exception("Job Scheduler host name missing."));

      if (_port == 0)
        throw (new Exception("Job Scheduler port missing."));

      udpSocket = new DatagramSocket();
      udpSocket.connect(InetAddress.getByName(_host), _port);

      // protocol=udp
      if (msg.indexOf("<?xml") == -1) {
        msg = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>" + msg + "\r\n";
      }

      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 {
      if (udpSocket != null)
        udpSocket.disconnect();

    }
  }
View Full Code Here

Examples of java.net.DatagramSocket

        strA = getSocket().getResponse();
        objAnswer = getAnswer(strA);
      }
      else
        if (objOptions.TransferMethod.isUdp()) {
          DatagramSocket udpSocket = null;
          int intPortNumber = 0;
          try {
            udpSocket = new DatagramSocket();
            intPortNumber = objOptions.PortNumber.value();
            InetAddress objInetAddress = objOptions.ServerName.getInetAddress();
            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;
          }
          finally {
            if (udpSocket != null) {
              logger.debug(String.format("Command sent using UDP to host '%1$s' at port '%2$d'", objOptions.ServerName.toString(), intPortNumber)  );
              udpSocket.disconnect();
              udpSocket = null;
            }
          }
        }
        else {
View Full Code Here

Examples of java.net.DatagramSocket

   */
  protected DatagramSocket getAuthSocket()
  throws SocketException {
    if (authSocket == null) {
      if (getListenAddress() == null)
        authSocket = new DatagramSocket(getAuthPort());
      else
        authSocket = new DatagramSocket(getAuthPort(), getListenAddress());
      authSocket.setSoTimeout(getSocketTimeout());
    }
    return authSocket;
  }
View Full Code Here

Examples of java.net.DatagramSocket

   */
  protected DatagramSocket getAcctSocket()
  throws SocketException {
    if (acctSocket == null) {
      if (getListenAddress() == null)
        acctSocket = new DatagramSocket(getAcctPort());
      else
        acctSocket = new DatagramSocket(getAcctPort(), getListenAddress());
      acctSocket.setSoTimeout(getSocketTimeout());
    }
    return acctSocket;
  }
View Full Code Here

Examples of java.net.DatagramSocket

    String host = address.substring(11, portSep); // 11 = "datagram://"

    if (host.equals("")) {
      // A server: Listen on a special port.
      socket = new DatagramSocket(port);
    } else {
      // A client: Any port will do
      socket = new DatagramSocket();
    }

    if (!timeouts)
      socket.setSoTimeout(0);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.