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


Java DatagramPacket.getOffset方法代码示例

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


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

示例1: run

import java.net.DatagramPacket; //导入方法依赖的package包/类
public void run()
{
    byte[] abyte = new byte[1024];

    while (!this.isInterrupted())
    {
        DatagramPacket datagrampacket = new DatagramPacket(abyte, abyte.length);

        try
        {
            this.socket.receive(datagrampacket);
        }
        catch (SocketTimeoutException var5)
        {
            continue;
        }
        catch (IOException ioexception)
        {
            LanServerDetector.logger.error((String)"Couldn\'t ping server", (Throwable)ioexception);
            break;
        }

        String s = new String(datagrampacket.getData(), datagrampacket.getOffset(), datagrampacket.getLength());
        LanServerDetector.logger.debug(datagrampacket.getAddress() + ": " + s);
        this.localServerList.func_77551_a(s, datagrampacket.getAddress());
    }

    try
    {
        this.socket.leaveGroup(this.broadcastAddress);
    }
    catch (IOException var4)
    {
        ;
    }

    this.socket.close();
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:39,代码来源:LanServerDetector.java

示例2: run

import java.net.DatagramPacket; //导入方法依赖的package包/类
@Override
public void run() {
    byte[] buffer = new byte[65535];
    DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
    while (true) {
        try {
            socket.receive(packet);
            byte channel = buffer[packet.getOffset()];
            byte[] data = new byte[packet.getLength() - 1];
            System.arraycopy(buffer, packet.getOffset() + 1, data, 0, data.length);
            
            if (channel > 0 && ROUTES.containsKey(channel)) {
                ROUTES.get(channel).send(data);
            }
            else {
                switch (channel) {
                    case CHANNEL_KILL_SOCKET: {
                        byte target = data[0];
                        ROUTES.get(target).killSocket();
                        break;
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:JoBa97,项目名称:UDPRelayClient,代码行数:29,代码来源:ChannelHandler.java

示例3: 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

示例4: run

import java.net.DatagramPacket; //导入方法依赖的package包/类
public void run()
{
    byte[] abyte = new byte[1024];

    while (!this.isInterrupted())
    {
        DatagramPacket datagrampacket = new DatagramPacket(abyte, abyte.length);

        try
        {
            this.socket.receive(datagrampacket);
        }
        catch (SocketTimeoutException var5)
        {
            continue;
        }
        catch (IOException ioexception)
        {
            LanServerDetector.LOGGER.error((String)"Couldn\'t ping server", (Throwable)ioexception);
            break;
        }

        String s = new String(datagrampacket.getData(), datagrampacket.getOffset(), datagrampacket.getLength());
        LanServerDetector.LOGGER.debug("{}: {}", new Object[] {datagrampacket.getAddress(), s});
        this.localServerList.addServer(s, datagrampacket.getAddress());
    }

    try
    {
        this.socket.leaveGroup(this.broadcastAddress);
    }
    catch (IOException var4)
    {
        ;
    }

    this.socket.close();
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:39,代码来源:LanServerDetector.java

示例5: executeDiscovery

import java.net.DatagramPacket; //导入方法依赖的package包/类
private void executeDiscovery() {
    try {
        final InetAddress inetAddress = InetAddress.getByName(MCAST_GROUP);
        final byte[] datagramBuffer = new byte[512];

        discoverySocket = new MulticastSocket(DISCOVERY_SOCKET_PORT);
        discoverySocket.setSoTimeout(0);
        discoverySocket.setReuseAddress(true);
        discoverySocket.joinGroup(inetAddress);

        while (!Thread.currentThread().isInterrupted()) {
            final DatagramPacket recv = new DatagramPacket(datagramBuffer, datagramBuffer.length);

            discoverySocket.receive(recv);

            final String responseMessage = new String(recv.getData(), recv.getOffset(), recv.getLength());
            final ZMoteDevice zmoteDevice = parseDiscoveryResponse(responseMessage);

            if (zmoteDevice != null) {
                discoveryResults.put(zmoteDevice.getUuid(), new ZMoteDiscoveryResult(zmoteDevice));
                notifyDiscovery(zmoteDevice);

                if (logger.isDebugEnabled()) {
                    logger.debug("Discovered ZMote device: {}", zmoteDevice.toString());
                }

            } else if (logger.isDebugEnabled()) {
                logger.debug("Discovered unsupported device: {}", responseMessage);
            }
        }
    } catch (final Exception e) {
        if ((e instanceof SocketException) && Thread.currentThread().isInterrupted()) {
            if (logger.isDebugEnabled()) {
                logger.debug("Discovery service worker has been terminated.");
            }
        } else if (logger.isWarnEnabled()) {
            logger.warn("ZMote device discovery failed!", e);
        }
    } finally {
        safeCloseDiscoverySocket();
    }
}
 
开发者ID:alexmaret,项目名称:openhab-binding-zmote,代码行数:43,代码来源:ZMoteDiscoveryService.java


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