import java.net.URI;
import org.activiti.engine.impl.util.json.JSONObject;
import org.apache.log4j.Logger;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;
public class MyWebSocketClient extends WebSocketClient{
Logger logger = Logger.getLogger(MyWebSocketClient.class);
public MyWebSocketClient(URI serverUri) {
super(serverUri);
}
@Override
public void onOpen(ServerHandshake arg0) {
// TODO Auto-generated method stub
logger.info("------ MyWebSocket onOpen ------");
}
@Override
public void onClose(int arg0, String arg1, boolean arg2) {
// TODO Auto-generated method stub
logger.info("------ MyWebSocket onClose ------");
}
@Override
public void onError(Exception arg0) {
// TODO Auto-generated method stub
logger.info("------ MyWebSocket onError ------");
}
@Override
public void onMessage(String arg0) {
// TODO Auto-generated method stub
logger.info("-------- 接收到服务端数据: " + arg0 + "--------");
}
}
MyTest 测试类
public class MyTest{
public static void main(String[] arg0){
MyWebSocketClient myClient = new MyWebSocketClient("此处为websocket服务端URI");
// 往websocket服务端发送数据
myClient.send("此为要发送的数据内容");
}
}
Linux公社的RSS地址:https://www.linuxidc.com/rssFeed.aspx