本文整理汇总了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;未经允许,请勿转载。 |
请发表评论