Java Code Examples for org.apache.catalina.websocket.WsOutbound#flush()

The following examples show how to use org.apache.catalina.websocket.WsOutbound#flush() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PushServlet.java    From ALLGO with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 2
Source File: PushServlet.java    From ALLGO with Apache License 2.0 6 votes vote down vote up
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();
		}
	}
}
 
Example 3
Source File: ActionListener.java    From ALLGO with Apache License 2.0 6 votes vote down vote up
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();
	}
	
}
 
Example 4
Source File: EchoStream.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 5
Source File: EchoStream.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 6
Source File: EchoStream.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 7
Source File: EchoStream.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 8
Source File: EchoStream.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 9
Source File: EchoStream.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@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();
}