websocket工具类

  • c6_541763
    了解作者
  • 820B
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-16 03:17
    上传日期
NULL 博文链接:https://yansxjl.iteye.com/blog/2392480
WebSocketUtil.rar
  • WebSocketUtil.java
    1.6KB
内容介绍
package com.infosys.utils; import com.alibaba.fastjson.JSON; import com.infosys.client.LoginClient; import javax.websocket.ContainerProvider; import javax.websocket.Session; import javax.websocket.WebSocketContainer; import java.net.URI; import java.util.HashMap; import java.util.Map; /** * Created by aust.ma on 5/11/2017. */ public class WebSocketUtil { public static boolean sendMessage(String sb,Class classObject) throws Exception { WebSocketContainer container = ContainerProvider.getWebSocketContainer(); String uri = "ws://10.158.139.63:8000"; try { Session session = container.connectToServer(classObject, new URI(uri)); session.getBasicRemote().sendText(sb); // 发送消息 Thread.sleep(2000); // 等待一小会 // session.close(); return true; } catch (Exception e) { throw e; } } // public String reciveMessage() throws Exception{ // // } public static void main(String[] args) { Map<String, String> map = new HashMap<String, String>(); map.put("Source","SERVICE"); map.put("Chattype","LOGOUT"); map.put("Userid","lily"); map.put("ClientUserid",""); map.put("Directtype","SERVICE"); map.put("Msgtext",""); map.put("Msgtype","CLIENTMSG"); try { System.out.println(WebSocketUtil.sendMessage(JSON.toJSONString(map),LoginClient.class)); } catch (Exception e) { e.printStackTrace(); } } }
评论
    相关推荐