Package java.net

Examples of java.net.DatagramSocket$Lock


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


   */
  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

         // 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

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

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

   */
  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

        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

   */
  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

   */
  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

    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

 
  public void testTestSocket(){
    try {
     
         // get a datagram socket
       DatagramSocket socket = new DatagramSocket();

           // send request
       byte[] buf = new byte[256];
       InetAddress address = InetAddress.getByName("192.168.0.41");
       DatagramPacket packet = new DatagramPacket(buf, buf.length, address, 4445);
      
       socket.setSoTimeout(1000);
      
       socket.send(packet);

           // get response
       packet = new DatagramPacket(buf, buf.length);
       socket.receive(packet);

       // display response
       String received = new String(packet.getData(), 0, packet.getLength());
       System.out.println("Date of the Moment: " + received);

       socket.close();
      
    } catch (Exception err) {
      log.error("[TestSocket] ",err);
    }
   
View Full Code Here

TOP

Related Classes of java.net.DatagramSocket$Lock

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.