问题描述
我已经插入连接代码,并使用websocket将redis的数据输入到Web服务器代码中,并且出现诸如标题之类的错误,我正在做一个聊天应用程序,现在该如何解决?,谢谢
@ServerEndpoint(value =“ / chatRoomServer”) 公共类ChatRoomServerEndpoint {
static Set<Session> users = Collections.synchronizedSet(new HashSet<>());
@Onopen
public void handleOpen(Session session) {
users.add(session);
}
@OnMessage
public void handleMessage(String message,Session userSession) throws IOException {
System.out.println("tien");
String username = (String) userSession.getUserProperties().get("username");
Jedis jedis = new Jedis("localhost");
System.out.println("Connection to server sucessfully");
System.out.println("Server is running: "+jedis.ping());
List<String> list = jedis.lrange("tutorial-list",5);
for(int i = 0; i<list.size(); i++) {
System.out.println("List of stored keys:: "+list.get(i));
}
if (username == null) {
userSession.getUserProperties().put("username",message);
userSession.getBasicRemote().sendText("System: you are connectd as " + message);
} else {
for (Session session : users) {
session.getBasicRemote().sendText(username + ": " + message);
}
}
}
@OnClose
public void handleClose(Session session) {
users.remove(session);
}
@OnError
public void handleError(Throwable t) {
t.printstacktrace();
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)