• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Datagram类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中javax.microedition.io.Datagram的典型用法代码示例。如果您正苦于以下问题:Java Datagram类的具体用法?Java Datagram怎么用?Java Datagram使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: execute

import javax.microedition.io.Datagram; //导入依赖的package包/类
protected boolean execute( DatagramConnection datagramConnection, Datagram datagram ) throws Exception {

        try {

            // blocks until data is received
            datagramConnection.receive( datagram );

            // do our execution on another thread so we can keep receiving new messages quickly
            ConnectionService.execute( Message.fromPacket( datagram.getData(), datagram.getOffset(), datagram.getLength() ) );
        }
        catch (InterruptedIOException e) {

            // do nothing
        }

        return true;
    }
 
开发者ID:MartinMReed,项目名称:ghostwriter-bb,代码行数:18,代码来源:IncomingThread.java


示例2: execute

import javax.microedition.io.Datagram; //导入依赖的package包/类
protected boolean execute( DatagramConnection datagramConnection, Datagram datagram ) throws Exception {

        long currentTimeMillis = System.currentTimeMillis();

        Stack messageStack = getMessageStack();
        if (messageStack.isEmpty() == false) {

            ConnectionService.getConnectionService().setKeepAlive( currentTimeMillis );

            Message message = (Message) messageStack.elementAt( 0 );
            messageStack.removeElementAt( 0 );

            byte[] packet = message.toPacket();

            datagram.setData( packet, 0, packet.length );
            datagramConnection.send( datagram );
        }
        else {

            Preferences preferences = PreferenceStore.instance().load();
            if (preferences.isKeepAlive() == false) {

                long keepAlive = ConnectionService.getConnectionService().getKeepAlive();
                long keepAliveDelay = preferences.getKeepAliveDelay() * 1000 * 60;
                if (currentTimeMillis - keepAliveDelay >= keepAlive) {

                    ConnectionService.reset();
                }
            }
        }

        // do not yield if we still have messages to send
        return messageStack.isEmpty();
    }
 
开发者ID:MartinMReed,项目名称:ghostwriter-bb,代码行数:35,代码来源:OutgoingThread.java


示例3: execute

import javax.microedition.io.Datagram; //导入依赖的package包/类
protected boolean execute( DatagramConnection datagramConnection, Datagram datagram ) throws Exception {

        Stack messageStack = getMessageStack();
        if (messageStack.isEmpty() == false) {

            Message message = (Message) messageStack.elementAt( 0 );
            messageStack.removeElementAt( 0 );

            switch (message.getCode()) {

                case CommunicationCode.PONG: {

                    pong( message );
                    break;
                }

                case CommunicationCode.SCREEN_CAPTURE_RESPONSE_A: {

                    screenCaptureA( message );
                    break;
                }

                case CommunicationCode.SCREEN_CAPTURE_RESPONSE_B: {

                    screenCaptureB( message );
                    break;
                }
            }
        }

        // do not yield if we still have messages to send
        return messageStack.isEmpty();
    }
 
开发者ID:MartinMReed,项目名称:ghostwriter-bb,代码行数:34,代码来源:ExecutorThread.java


示例4: getTime

import javax.microedition.io.Datagram; //导入依赖的package包/类
public long getTime() throws Exception {
    if (Logger.BUILD_DEBUG && LOG) {
        Logger.log("NTP server: " + server);
    }
    byte[] buf = new NtpMessage().toByteArray();
    DatagramConnection conn = Connections.udp(server, 123);
    try {
        Datagram dtgm = conn.newDatagram(buf, buf.length);

        // Set the transmit timestamp *just* before sending the packet
        // ToDo: Does this actually improve performance or not?
        NtpMessage.encodeTimestamp(dtgm.getData(), 40,
                (System.currentTimeMillis() / 1000.0) + 2208988800.0);

        conn.send(dtgm);


        // Get response
        if (Logger.BUILD_DEBUG && LOG) {
            Logger.log("NTP request sent (" + dtgm.getLength() + " bytes), waiting for response...");
        }
        //dtgm = conn.newDatagram(1024);
        conn.receive(dtgm);
        if (Logger.BUILD_DEBUG && LOG) {
            Logger.log("NTP response received (" + dtgm.getLength() + " bytes)");
        }

        // Immediately record the incoming timestamp
        double destinationTimestamp =
                (System.currentTimeMillis() / 1000.0) + 2208988800.0;


        // Process response
        NtpMessage msg = new NtpMessage(dtgm.getData());

        // Corrected, according to RFC2030 errata
        double roundTripDelay = (destinationTimestamp - msg.originateTimestamp)
                - (msg.transmitTimestamp - msg.receiveTimestamp);

        double localClockOffset =
                ((msg.receiveTimestamp - msg.originateTimestamp)
                + (msg.transmitTimestamp - destinationTimestamp)) / 2;


        // Display response
        if (Logger.BUILD_DEBUG && LOG) {
            Logger.log(msg.toString());

            Logger.log("Dest. timestamp:     "
                    + NtpMessage.timestampToString(destinationTimestamp));

            Logger.log("Round-trip delay: " + (roundTripDelay * 1000) + " ms");

            Logger.log("Local clock offset: " + (localClockOffset * 1000) + " ms");
        }
        return (long) msg.getTime() / 1000;
    } finally {
        conn.close();
    }
}
 
开发者ID:fclairamb,项目名称:tc65lib,代码行数:61,代码来源:SntpClient.java


示例5: execute

import javax.microedition.io.Datagram; //导入依赖的package包/类
protected abstract boolean execute( DatagramConnection datagramConnection, Datagram datagram ) throws Exception; 
开发者ID:MartinMReed,项目名称:ghostwriter-bb,代码行数:2,代码来源:AbstractWorkerThread.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AcceptingChannel类代码示例发布时间:2022-05-23
下一篇:
Java DERSequenceGenerator类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap