当前位置: 首页>>代码示例>>Java>>正文


Java DatagramSocket.setBroadcast方法代码示例

本文整理汇总了Java中java.net.DatagramSocket.setBroadcast方法的典型用法代码示例。如果您正苦于以下问题:Java DatagramSocket.setBroadcast方法的具体用法?Java DatagramSocket.setBroadcast怎么用?Java DatagramSocket.setBroadcast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.net.DatagramSocket的用法示例。


在下文中一共展示了DatagramSocket.setBroadcast方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: BroadcastHandler

import java.net.DatagramSocket; //导入方法依赖的package包/类
BroadcastHandler(Looper looper, String hostName, long broadcastInterval) {
            super(looper);
            mHostName = hostName;
            mBroadcastInterval = broadcastInterval;
            //Open a random port to send the package
            try {
                mSocket = new DatagramSocket();
                mSocket.setBroadcast(true);
            } catch (SocketException e) {
//                TODO: handle
            }
        }
 
开发者ID:adroitandroid,项目名称:Near,代码行数:13,代码来源:UdpBroadcastService.java

示例3: 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.setBroadcast方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。