本文整理汇总了Java中javax.websocket.Session.getBasicRemote方法的典型用法代码示例。如果您正苦于以下问题:Java Session.getBasicRemote方法的具体用法?Java Session.getBasicRemote怎么用?Java Session.getBasicRemote使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.websocket.Session
的用法示例。
在下文中一共展示了Session.getBasicRemote方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onOpen
import javax.websocket.Session; //导入方法依赖的package包/类
@Override
public void onOpen(Session session, EndpointConfig arg1) {
final RemoteEndpoint.Basic remote = session.getBasicRemote();
session.addMessageHandler(new MessageHandler.Whole<String>() {
public void onMessage(String text) {
try {
remote.sendText(text.toUpperCase());
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
});
}
示例2: onOpen
import javax.websocket.Session; //导入方法依赖的package包/类
@Override
public void onOpen(Session session, EndpointConfig endpointConfig) {
RemoteEndpoint.Basic remoteEndpointBasic = session.getBasicRemote();
session.addMessageHandler(new EchoMessageHandlerText(remoteEndpointBasic));
session.addMessageHandler(new EchoMessageHandlerBinary(remoteEndpointBasic));
}
示例3: onMessage
import javax.websocket.Session; //导入方法依赖的package包/类
@OnMessage
public void onMessage(Session session, String msg) throws IOException {
if (started) {
return;
}
synchronized (this) {
if (started) {
return;
} else {
started = true;
}
}
System.out.println("Received " + msg + ", now sending data");
session.getUserProperties().put(
"org.apache.tomcat.websocket.BLOCKING_SEND_TIMEOUT",
Long.valueOf(SEND_TIME_OUT_MILLIS));
Basic remote = session.getBasicRemote();
remote.setBatchingAllowed(true);
for (int i = 0; i < MESSAGE_COUNT; i++) {
remote.sendText(MESSAGE);
if (i % (MESSAGE_COUNT * 0.4) == 0) {
remote.setBatchingAllowed(false);
remote.setBatchingAllowed(true);
}
}
// Flushing should happen automatically on session close
session.close();
}