本文整理汇总了Java中org.apache.catalina.websocket.WsOutbound.flush方法的典型用法代码示例。如果您正苦于以下问题:Java WsOutbound.flush方法的具体用法?Java WsOutbound.flush怎么用?Java WsOutbound.flush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.catalina.websocket.WsOutbound
的用法示例。
在下文中一共展示了WsOutbound.flush方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onOpen
import org.apache.catalina.websocket.WsOutbound; //导入方法依赖的package包/类
@Override
protected void onOpen(WsOutbound outbound) {
if(uid == -1){ //过期用户直接下线
Map<String, Object> outMap = new HashMap<String, Object>();
outMap.put("response", "notlogin");
String jsonString = JSONObject.fromObject(outMap).toString();
CharBuffer buffer = CharBuffer.wrap(jsonString);
try {
outbound.writeTextMessage(buffer);
outbound.flush();
} catch (IOException e) {
e.printStackTrace();
}
}else{
userMap.put(uid, outbound);
System.out.println("[上线]==>uid:"+uid+"在线用户==>"+userMap.size());
sendUnread(outbound); //登录即检查有没有未读消息
}
super.onOpen(outbound);
}
示例2: sendUnread
import org.apache.catalina.websocket.WsOutbound; //导入方法依赖的package包/类
private void sendUnread(WsOutbound outbound){
Map<String, Object> outMap = new HashMap<String, Object>();
outMap.put("response", "remind_unread");
UnreadDAO dao = new UnreadDAOimpl();
List<UnreadVo> list = dao.getUnread(uid);
if(list != null){
outMap.put("remind_unread", list);
String jsonString = JSONObject.fromObject(outMap).toString();
CharBuffer buffer = CharBuffer.wrap(jsonString);
try {
outbound.writeTextMessage(buffer);
outbound.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
}
示例3: sendUnread
import org.apache.catalina.websocket.WsOutbound; //导入方法依赖的package包/类
private void sendUnread(UnreadVo unread, WsOutbound outbound) {
Map<String, Object> outMap = new HashMap<String, Object>();
outMap.put("response", "remind_unread");
List<UnreadVo> list = new ArrayList<UnreadVo>();
list.add(unread);
outMap.put("remind_unread", list);
String jsonString = JSONObject.fromObject(outMap).toString();
CharBuffer buffer = CharBuffer.wrap(jsonString);
try {
outbound.writeTextMessage(buffer);
outbound.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
示例4: onBinaryData
import org.apache.catalina.websocket.WsOutbound; //导入方法依赖的package包/类
@Override
protected void onBinaryData(InputStream is) throws IOException {
// Simply echo the data to back to the client.
WsOutbound outbound = getWsOutbound();
int i = is.read();
while (i != -1) {
outbound.writeBinaryData(i);
i = is.read();
}
outbound.flush();
}
示例5: onTextData
import org.apache.catalina.websocket.WsOutbound; //导入方法依赖的package包/类
@Override
protected void onTextData(Reader r) throws IOException {
// Simply echo the data to back to the client.
WsOutbound outbound = getWsOutbound();
int c = r.read();
while (c != -1) {
outbound.writeTextData((char) c);
c = r.read();
}
outbound.flush();
}