當前位置: 首頁>>代碼示例>>Java>>正文


Java DatagramSocket.setReuseAddress方法代碼示例

本文整理匯總了Java中java.net.DatagramSocket.setReuseAddress方法的典型用法代碼示例。如果您正苦於以下問題:Java DatagramSocket.setReuseAddress方法的具體用法?Java DatagramSocket.setReuseAddress怎麽用?Java DatagramSocket.setReuseAddress使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.net.DatagramSocket的用法示例。


在下文中一共展示了DatagramSocket.setReuseAddress方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: BLDevice

import java.net.DatagramSocket; //導入方法依賴的package包/類
/**
 * Constructs a <code>BLDevice</code>, with a device type (constants),
 * hostname and MAC address
 * 
 * @param deviceType
 *            Device type constants (<code>BLDevice.DEV_*</code>)
 * @param devDesc
 *            Friendly device description
 * @param host
 *            Hostname of target Broadlink device
 * @param mac
 *            MAC address of target Broadlink device
 * @throws IOException
 *             Problems on constructing a datagram socket
 */
protected BLDevice(short deviceType, String deviceDesc, String host, Mac mac) throws IOException {
    key = INITIAL_KEY;
    iv = INITIAL_IV;
    id = new byte[] { 0, 0, 0, 0 };

    pktCount = new Random().nextInt(0xffff);
    // pktCount = 0;

    this.deviceType = deviceType;
    this.deviceDesc = deviceDesc;
    
    this.host = host;
    this.mac = mac;

    sock = new DatagramSocket(0);
    sock.setReuseAddress(true);
    sock.setBroadcast(true);
}
 
開發者ID:mob41,項目名稱:broadlink-java-api,代碼行數:34,代碼來源:BLDevice.java

示例2: init

import java.net.DatagramSocket; //導入方法依賴的package包/類
@Override
public void init(DaemonContext context) throws Exception {
  System.err.println("Initializing privileged NFS client socket...");
  NfsConfiguration conf = new NfsConfiguration();
  int clientPort = conf.getInt(NfsConfigKeys.DFS_NFS_REGISTRATION_PORT_KEY,
      NfsConfigKeys.DFS_NFS_REGISTRATION_PORT_DEFAULT);
  if (clientPort < 1 || clientPort > 1023) {
    throw new RuntimeException("Must start privileged NFS server with '" +
        NfsConfigKeys.DFS_NFS_REGISTRATION_PORT_KEY + "' configured to a " +
        "privileged port.");
  }
  registrationSocket = new DatagramSocket(
      new InetSocketAddress("localhost", clientPort));
  registrationSocket.setReuseAddress(true);
  args = context.getArguments();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:17,代碼來源:PrivilegedNfsGatewayStarter.java

示例3: createSocket

import java.net.DatagramSocket; //導入方法依賴的package包/類
protected DatagramSocket createSocket() throws SocketException {
    DatagramSocket socket = new DatagramSocket();
    socket.setReuseAddress(true);
    return socket;
}
 
開發者ID:Orange-OpenSource,項目名稱:OCast-Java,代碼行數:6,代碼來源:SSDPDiscovery.java

示例4: sendPkt

import java.net.DatagramSocket; //導入方法依賴的package包/類
/**
 * Sends a compiled packet to a destination host and port, and receives a
 * datagram from the source port specified.
 * 
 * @param pkt
 *            The compiled packet to be sent
 * @param sourceIpAddr
 *            Source IP address to be binded for receiving datagrams
 * @param sourcePort
 *            Source Port to be bineded for receiving datagrams
 * @param destIpAddr
 *            Destination IP address
 * @param destPort
 *            Destination Port
 * @param timeout
 *            Socket timeout. 0 will disable the timeout
 * @param bufSize
 *            Receiving datagram's buffer size
 * @return The received datagram
 * @throws IOException
 *             Thrown if socket timed out, cannot bind source IP and source
 *             port, no permission, etc.
 */
public static DatagramPacket sendPkt(Packet pkt, InetAddress sourceIpAddr, int sourcePort, InetAddress destIpAddr,
        int destPort, int timeout, int bufSize) throws IOException {
    DatagramSocket sock = new DatagramSocket(sourcePort, sourceIpAddr);

    sock.setBroadcast(true);
    sock.setReuseAddress(true);

    DatagramPacket recePkt = sendPkt(sock, pkt, sourceIpAddr, sourcePort, destIpAddr, destPort, timeout, bufSize);
    sock.close();

    return recePkt;
}
 
開發者ID:mob41,項目名稱:broadlink-java-api,代碼行數:36,代碼來源:BLDevice.java


注:本文中的java.net.DatagramSocket.setReuseAddress方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。