码迷,mamicode.com
首页 > Web开发 > 详细

基于tomcat7 的websocket

时间:2014-09-24 14:43:57      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:style   http   io   os   使用   java   ar   sp   art   

基于tomcat7.0使用websocket

jdk1.7

tomcat7.0

创建WebSocketServlet

package com.biz.action.servlet;


import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServletRequest;


import org.apache.catalina.websocket.StreamInbound;

import org.apache.catalina.websocket.WebSocketServlet;


import com.biz.websocket.LogMessageInbound;

@WebServlet("/log")

public class LogSocketServlet extends WebSocketServlet {

/**

*/

private static final long serialVersionUID = 5050900528174933757L;


public LogSocketServlet(){

System.out.println("logSocket create");

}


@Override

protected StreamInbound createWebSocketInbound(String arg0,

HttpServletRequest request) {

                        return new LogMessageInbound();

}


}

创建MessageInbound


package com.biz.websocket;


import java.io.IOException;

import java.nio.ByteBuffer;

import java.nio.CharBuffer;


import org.apache.catalina.websocket.MessageInbound;

import org.apache.catalina.websocket.WsOutbound;


import redis.clients.jedis.Jedis;


import com.biz.thread.LogThread;

import com.core.redis.MyRedisListener;

import com.core.redis.handler.MyHandler;


public class LogMessageInbound extends MessageInbound{


@Override

protected void onOpen(WsOutbound outbound) {

System.out.println("onOpen start");


System.out.println("onOpen end");

}

@Override

protected void onClose(int state) {

System.out.println("state="+state);

}

@Override

protected void onBinaryMessage(ByteBuffer arg0) throws IOException {


}


@Override

protected void onTextMessage(CharBuffer arg0) throws IOException {


}


}


基于tomcat7 的websocket

标签:style   http   io   os   使用   java   ar   sp   art   

原文地址:http://my.oschina.net/u/567457/blog/317855

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!