Package java.net

Examples of java.net.DatagramSocket$Lock


    final byte[] buf = new byte[DATAGRAM_MAX_SIZE];
    final DatagramPacket packet = new DatagramPacket(buf, buf.length);

    protected NetServerIn(String name, Logger logmon) throws IOException {
      super(name + ".NetServerIn", logmon);
      socket = new DatagramSocket(port);
      socket.setReceiveBufferSize(AgentServer.getInteger("UDPReceiveBufferSize", 1048576).intValue());
      socket.setSendBufferSize(AgentServer.getInteger("UDPSendBufferSize", 8192).intValue());
      if (logmon.isLoggable(BasicLevel.DEBUG)) {
        logmon.log(BasicLevel.DEBUG, this.getName() + ", socket buffer sizes: Receive:"
            + socket.getReceiveBufferSize() + " Send:" + socket.getSendBufferSize());
View Full Code Here


            } catch (SocketException exc) {
              if (logmon.isLoggable(BasicLevel.DEBUG)) {
                logmon.log(BasicLevel.DEBUG, this.getName() + ", waiting messages has been interrupted ", exc);
              }
              if (running && socket.isClosed()) {
                socket = new DatagramSocket(port);
                socket.setReceiveBufferSize(socketReceiveBufferSize);
                socket.setSendBufferSize(socketSendBufferSize);
                if (logmon.isLoggable(BasicLevel.DEBUG)) {
                  logmon.log(BasicLevel.DEBUG, this.getName()
                      + ", socket reinitialized: buffer sizes: Receive:" + socket.getReceiveBufferSize()
View Full Code Here

   * @param udpPort The UDP port of the server.
   * @param timeoutMillis The number of milliseconds to wait for a response.
   * @return the first server found, or null if no server responded.
   */
  public InetAddress discoverHost (int udpPort, int timeoutMillis) {
    DatagramSocket socket = null;
    try {
      socket = new DatagramSocket();
      broadcast(udpPort, socket);
      socket.setSoTimeout(timeoutMillis);
      DatagramPacket packet = new DatagramPacket(new byte[0], 0);
      try {
        socket.receive(packet);
      } catch (SocketTimeoutException ex) {
        if (INFO) info("kryonet", "Host discovery timed out.");
        return null;
      }
      if (INFO) info("kryonet", "Discovered server: " + packet.getAddress());
      return packet.getAddress();
    } catch (IOException ex) {
      if (ERROR) error("kryonet", "Host discovery failed.", ex);
      return null;
    } finally {
      if (socket != null) socket.close();
    }
  }
View Full Code Here

   * @param udpPort The UDP port of the server.
   * @param timeoutMillis The number of milliseconds to wait for a response.
   */
  public List<InetAddress> discoverHosts (int udpPort, int timeoutMillis) {
    List<InetAddress> hosts = new ArrayList<InetAddress>();
    DatagramSocket socket = null;
    try {
      socket = new DatagramSocket();
      broadcast(udpPort, socket);
      socket.setSoTimeout(timeoutMillis);
      while (true) {
        DatagramPacket packet = new DatagramPacket(new byte[0], 0);
        try {
          socket.receive(packet);
        } catch (SocketTimeoutException ex) {
          if (INFO) info("kryonet", "Host discovery timed out.");
          return hosts;
        }
        if (INFO) info("kryonet", "Discovered server: " + packet.getAddress());
        hosts.add(packet.getAddress());
      }
    } catch (IOException ex) {
      if (ERROR) error("kryonet", "Host discovery failed.", ex);
      return hosts;
    } finally {
      if (socket != null) socket.close();
    }
  }
View Full Code Here

       implements Runnable {
      static final int MAX_PACKET_SIZE = 1024 * 10;
      public void run() {
         try {
            try {
               socketUDP = new DatagramSocket(socketUrl.getPort(), socketUrl.getInetAddress());
            }
            catch (java.net.SocketException e) {
               log.severe("Cannot open UDP socket '" + socketUrl.getUrl() + "' : " + e.toString());
               return;
            }
View Full Code Here

            closeTimeout = Math.max( SO_TIMEOUT, timeout );
        }
        // If socket is still good, the new closeTimeout will
        // be ignored; see tryClose comment.
        if( socket == null ) {
            socket = new DatagramSocket( lport, laddr );
            thread = new Thread( this, "JCIFS-NameServiceClient" );
            thread.setDaemon( true );
            thread.start();
        }
    }
View Full Code Here

    ((MulticastSocket)dataSock).joinGroup(addr);
    ((MulticastSocket)dataSock).setTimeToLive(ttl);
    ((MulticastSocket)ctrlSock).joinGroup(addr);
    ((MulticastSocket)ctrlSock).setTimeToLive(ttl);
      } else {
    dataSock = new DatagramSocket(port, InetAddress.getLocalHost());
    ctrlSock = new DatagramSocket(port+1, InetAddress.getLocalHost());
      }


  } catch (SocketException e) {
      throw new IOException(e.getMessage());
View Full Code Here

        /* Bind server socket */
        if (listeningSocketConfiguration.getTransport().equals(TunnelConfiguration.UDP_TUNNEL)) {
            // #ifdef DEBUG
            log.info("Creating UDP server socket on port " + listeningSocketConfiguration.getSourcePort()); //$NON-NLS-1$
            // #endif
            datagramSocket = new DatagramSocket(listeningSocketConfiguration.getSourcePort());
        } else {
            // #ifdef DEBUG
          if(listeningSocketConfiguration.getSourcePort() == 0)
            log.info("Creating TCP server socket random port") ; //$NON-NLS-1$
          else
View Full Code Here

    super();
    this.eagleDNS = eagleDNS;
    this.addr = addr;
    this.port = port;

    socket = new DatagramSocket(port, addr);

    this.setDaemon(true);
    this.start();
  }
View Full Code Here

  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

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.