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


Java DatagramPacket.setData方法代码示例

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


在下文中一共展示了DatagramPacket.setData方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: mockServer

import java.net.DatagramPacket; //导入方法依赖的package包/类
/**
 * MockServer plays the role of peer C. Respond to two requests for votes
 * with vote for self and then Assert.fail. 
 */
void mockServer() throws InterruptedException, IOException {          
    byte b[] = new byte[36];
    ByteBuffer responseBuffer = ByteBuffer.wrap(b);
    DatagramPacket packet = new DatagramPacket(b, b.length);
    QuorumServer server = peers.get(Long.valueOf(2));
    DatagramSocket udpSocket = new DatagramSocket(server.addr.getPort());
    LOG.info("In MockServer");
    mockLatch.countDown();
    Vote current = new Vote(2, 1);
    for (int i=0;i<2;++i) {
        udpSocket.receive(packet);
        responseBuffer.rewind();
        LOG.info("Received " + responseBuffer.getInt() + " " + responseBuffer.getLong() + " " + responseBuffer.getLong());
        LOG.info("From " + packet.getSocketAddress());
        responseBuffer.clear();
        responseBuffer.getInt(); // Skip the xid
        responseBuffer.putLong(2);
        
        responseBuffer.putLong(current.getId());
        responseBuffer.putLong(current.getZxid());
        packet.setData(b);
        udpSocket.send(packet);
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:29,代码来源:LENonTerminateTest.java

示例2: receive

import java.net.DatagramPacket; //导入方法依赖的package包/类
public synchronized void receive(DatagramPacket p) throws IOException {
	TunData td=null;
	try {
		td=packetList.take();
		p.setData(td.data);
		p.setLength(td.data.length);
		p.setAddress(td.tun.remoteAddress);
		p.setPort(CapEnv.toUnsigned(td.tun.remotePort));
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
}
 
开发者ID:breakEval13,项目名称:NSS,代码行数:13,代码来源:VDatagramSocket.java

示例3: sendData

import java.net.DatagramPacket; //导入方法依赖的package包/类
private boolean sendData(byte[] data) {
    DatagramPacket packet = new DatagramPacket(sendBuffer, DAEMON_BUF_RECEIVE_SIZE, address);
    packet.setData(data);
    try {
        logger.debug("Sending UDP packet.");
        daemonSocket.send(packet);
    } catch (IOException e) {
        logger.error("Exception while sending segment over UDP.", e);
        return false;
    }
    return true;
}
 
开发者ID:aws,项目名称:aws-xray-sdk-java,代码行数:13,代码来源:UDPEmitter.java

示例4: main

import java.net.DatagramPacket; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {

        byte b1[] = new byte[1024];
        DatagramPacket p = new DatagramPacket(b1, 512, 512 );

        byte b2[] = new byte[20];
        p.setData(b2);

        if (p.getOffset() != 0) {
            throw new Exception("setData(byte[]) didn't reset offset");
        }
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:13,代码来源:Offset.java

示例5: run

import java.net.DatagramPacket; //导入方法依赖的package包/类
@Override
public void run()
{
    byte[] buf = new byte[512];
    DatagramPacket packet = new DatagramPacket(buf, buf.length);

    while (true)
    {
        try
        {
            checkSocket();
            packet.setData(buf);
            try {
                socket.receive(packet);
                processNetworkData(packet.getAddress(), buf, packet.getLength());
            } catch (SocketTimeoutException ste) {
            }

            checkForTimeouts();
        }
        catch (Exception e)
        {
            log.log(Level.WARNING, "error in receiverthread: " + e, e);
            try { Thread.sleep(1000); } catch (InterruptedException ie) {}
        }
    }
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:28,代码来源:Discovery.java

示例6: prepareDatagramPacket

import java.net.DatagramPacket; //导入方法依赖的package包/类
private void prepareDatagramPacket(InetAddress address, int port){
    byte[] buffer = processOutputData();
    dataPacket = new DatagramPacket(buffer,buffer.length, address, port);
    dataPacket.setData(buffer);
}
 
开发者ID:Obsidiam,项目名称:amelia,代码行数:6,代码来源:UDPThread.java


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