1.去掉socket的注释
This commit is contained in:
parent
055c69d6f3
commit
d520a2053c
|
@ -1,70 +1,70 @@
|
|||
//package org.aohe.web;
|
||||
//
|
||||
//
|
||||
//import cn.hutool.log.Log;
|
||||
//import cn.hutool.log.LogFactory;
|
||||
//import cn.hutool.log.StaticLog;
|
||||
//import org.aohe.result.R;
|
||||
//import org.java_websocket.WebSocket;
|
||||
//import org.java_websocket.handshake.ClientHandshake;
|
||||
//import org.java_websocket.server.WebSocketServer;
|
||||
//
|
||||
//import java.net.InetSocketAddress;
|
||||
//import java.net.UnknownHostException;
|
||||
//
|
||||
//import static org.aohe.control.Operational.selectOperational;
|
||||
//
|
||||
//public class SocketServer extends WebSocketServer {
|
||||
//
|
||||
// private static final Log log = LogFactory.get();
|
||||
//
|
||||
// public SocketServer(int port) throws UnknownHostException {
|
||||
// super(new InetSocketAddress(port));
|
||||
// }
|
||||
//
|
||||
// public SocketServer(InetSocketAddress address) {
|
||||
// super(address);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onOpen(WebSocket conn, ClientHandshake handshake) {
|
||||
// //conn.send("Welcome to the server!"); // This method sends a message to the new client
|
||||
// //broadcast("new connection: " + handshake.getResourceDescriptor()); // This method sends a message to all clients connected
|
||||
// //System.out.println(conn.getRemoteSocketAddress().getAddress().getHostAddress() + " entered the room!");
|
||||
// StaticLog.info("ws用户已连接");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onClose(WebSocket conn, int code, String reason, boolean remote) {
|
||||
// StaticLog.info("ws用户关闭连接");
|
||||
// //这里执行关闭扫描仪连接
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onMessage(WebSocket conn, String message) {
|
||||
// StaticLog.info("用户发送了数据:\n"+message);
|
||||
// conn.send(selectOperational(message));
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(WebSocket conn, Exception ex) {
|
||||
// ex.printStackTrace();
|
||||
// if (conn != null) {
|
||||
// conn.send(R.fail("error").toJsonStr());
|
||||
// //绑定不到就退出
|
||||
// //System.exit(0);
|
||||
// // some errors like port binding failed may not be assignable to a specific
|
||||
// // websocket
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onStart() {
|
||||
// System.out.println("Server started!");
|
||||
// setConnectionLostTimeout(0);
|
||||
// setConnectionLostTimeout(100);
|
||||
//
|
||||
// }
|
||||
//
|
||||
//}
|
||||
package org.aohe.web;
|
||||
|
||||
|
||||
import cn.hutool.log.Log;
|
||||
import cn.hutool.log.LogFactory;
|
||||
import cn.hutool.log.StaticLog;
|
||||
import org.aohe.result.R;
|
||||
import org.java_websocket.WebSocket;
|
||||
import org.java_websocket.handshake.ClientHandshake;
|
||||
import org.java_websocket.server.WebSocketServer;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import static org.aohe.control.Operational.selectOperational;
|
||||
|
||||
public class SocketServer extends WebSocketServer {
|
||||
|
||||
private static final Log log = LogFactory.get();
|
||||
|
||||
public SocketServer(int port) throws UnknownHostException {
|
||||
super(new InetSocketAddress(port));
|
||||
}
|
||||
|
||||
public SocketServer(InetSocketAddress address) {
|
||||
super(address);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(WebSocket conn, ClientHandshake handshake) {
|
||||
//conn.send("Welcome to the server!"); // This method sends a message to the new client
|
||||
//broadcast("new connection: " + handshake.getResourceDescriptor()); // This method sends a message to all clients connected
|
||||
//System.out.println(conn.getRemoteSocketAddress().getAddress().getHostAddress() + " entered the room!");
|
||||
StaticLog.info("ws用户已连接");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(WebSocket conn, int code, String reason, boolean remote) {
|
||||
StaticLog.info("ws用户关闭连接");
|
||||
//这里执行关闭扫描仪连接
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(WebSocket conn, String message) {
|
||||
StaticLog.info("用户发送了数据:\n"+message);
|
||||
conn.send(selectOperational(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(WebSocket conn, Exception ex) {
|
||||
ex.printStackTrace();
|
||||
if (conn != null) {
|
||||
conn.send(R.fail("error").toJsonStr());
|
||||
//绑定不到就退出
|
||||
//System.exit(0);
|
||||
// some errors like port binding failed may not be assignable to a specific
|
||||
// websocket
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
System.out.println("Server started!");
|
||||
setConnectionLostTimeout(0);
|
||||
setConnectionLostTimeout(100);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue