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


Java DatagramConnection类代码示例

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


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

示例1: execute

import javax.microedition.io.DatagramConnection; //导入依赖的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: UDPTransport

import javax.microedition.io.DatagramConnection; //导入依赖的package包/类
public UDPTransport(DatagramConnection socket, int mtu)
    throws IOException
{
    //
    // In 1.3 and earlier sockets were bound and connected during creation
    //
    //if (!socket.isBound() || !socket.isConnected())
    //{
    //    throw new IllegalArgumentException("'socket' must be bound and connected");
    //}

    this.socket = socket;

    // NOTE: As of JDK 1.6, can use NetworkInterface.getMTU

    this.receiveLimit = mtu - MIN_IP_OVERHEAD - UDP_OVERHEAD;
    this.sendLimit = mtu - MAX_IP_OVERHEAD - UDP_OVERHEAD;
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:19,代码来源:UDPTransport.java

示例3: execute

import javax.microedition.io.DatagramConnection; //导入依赖的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

示例4: execute

import javax.microedition.io.DatagramConnection; //导入依赖的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

示例5: ConnectionService

import javax.microedition.io.DatagramConnection; //导入依赖的package包/类
private ConnectionService() throws Exception {

        Preferences preferences = PreferenceStore.instance().load();

        String serverDomain = preferences.getServerDomain();
        StringBuffer outgoingAddress = new StringBuffer( "datagram://" + serverDomain + ":" + Ports.SERVER + ";" + Ports.SERVER );

        getConnectParams( outgoingAddress );

        DatagramConnection datagramConnection = (DatagramConnection) Connector.open( outgoingAddress.toString() );
        setDatagramConnection( datagramConnection );

        setOutgoingThread( new OutgoingThread( datagramConnection ) );
        setIncomingThread( new IncomingThread( datagramConnection ) );
        setExecutorThread( new ExecutorThread( datagramConnection ) );

        setKeepAlive( System.currentTimeMillis() );
    }
 
开发者ID:MartinMReed,项目名称:ghostwriter-bb,代码行数:19,代码来源:ConnectionService.java

示例6: getTime

import javax.microedition.io.DatagramConnection; //导入依赖的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

示例7: OutgoingThread

import javax.microedition.io.DatagramConnection; //导入依赖的package包/类
public OutgoingThread(DatagramConnection datagramConnection) {

        super( datagramConnection );
    }
 
开发者ID:MartinMReed,项目名称:ghostwriter-bb,代码行数:5,代码来源:OutgoingThread.java

示例8: IncomingThread

import javax.microedition.io.DatagramConnection; //导入依赖的package包/类
public IncomingThread(DatagramConnection datagramConnection) {

        super( datagramConnection );
    }
 
开发者ID:MartinMReed,项目名称:ghostwriter-bb,代码行数:5,代码来源:IncomingThread.java

示例9: getDatagramConnection

import javax.microedition.io.DatagramConnection; //导入依赖的package包/类
private DatagramConnection getDatagramConnection() {

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

示例10: setDatagramConnection

import javax.microedition.io.DatagramConnection; //导入依赖的package包/类
private void setDatagramConnection( DatagramConnection datagramConnection ) {

        this.datagramConnection = datagramConnection;
    }
 
开发者ID:MartinMReed,项目名称:ghostwriter-bb,代码行数:5,代码来源:ConnectionService.java

示例11: AbstractWorkerThread

import javax.microedition.io.DatagramConnection; //导入依赖的package包/类
public AbstractWorkerThread(DatagramConnection datagramConnection) {

        setDatagramConnection( datagramConnection );
    }
 
开发者ID:MartinMReed,项目名称:ghostwriter-bb,代码行数:5,代码来源:AbstractWorkerThread.java

示例12: ExecutorThread

import javax.microedition.io.DatagramConnection; //导入依赖的package包/类
public ExecutorThread(DatagramConnection datagramConnection) {

        super( datagramConnection );

        screenCaptureReset();
    }
 
开发者ID:MartinMReed,项目名称:ghostwriter-bb,代码行数:7,代码来源:ExecutorThread.java

示例13: execute

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


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