当前位置: 首页> 健康> 科研 > 网站建立时间怎么查_免费的好网站_如何联系百度推广_推广策划方案怎么做

网站建立时间怎么查_免费的好网站_如何联系百度推广_推广策划方案怎么做

时间:2025/9/9 4:20:39来源:https://blog.csdn.net/changxiang/article/details/147372727 浏览次数:0次
网站建立时间怎么查_免费的好网站_如何联系百度推广_推广策划方案怎么做

一:引入依赖:

<!--WebSocket专用--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-websocket</artifactId></dependency><dependency><groupId>org.glassfish.tyrus.bundles</groupId><artifactId>tyrus-standalone-client</artifactId><version>2.1.5</version></dependency><!--WebSocket end-->

二:写Service:

@Component
@ServerEndpoint("/websocket/tterm")
public class WebSocketServerEterm {
@OnOpen
public void onOpen(Session session) {try {_socket = new Socket(serverIp, serverPort); // 使用配置中的IP和端口if (_socket.isConnected()) {。。。}
}}
@OnMessage
public void onMessage(String command, Session session) 
@OnClose
public void onClose(Session session) {try {if (_socket != null)_socket.close();System.out.println("Socket连接关闭: " + session.getId());} catch (IOException e) {System.err.println("关闭Socket资源失败:" + e.getMessage());}
}

 三、使用

const WS_BASE_URL = import.meta.env.VITE_WS_URL;
const url = WS_BASE_URL ? `${WS_BASE_URL}/websocket/tterm` : null;
 

// 切换模态框
const toggleEtermModal = async () => {if (!url) {message.error('WebSocket服务未配置');return;}etermVisible.value = !etermVisible.value;if (etermVisible.value) {try {await nextTick();document.querySelector('.eterm-input')?.focus();etermLoading.value = true;await etermApi.connect(url, {onMessage: (data) => {etermList.value.push({command: '',response: data});scrollToBottom();},onOpen: () => {socketConnected.value = true;etermList.value.push({command: '',response: '>>> 连接成功'});},onClose: () => {socketConnected.value = false;}});} catch (error) {message.error(`连接失败: ${error.message}`);etermVisible.value = false;} finally {etermLoading.value = false;}} else {etermApi.exit();}
};

四、正式环境需要结合NGINX:
 

# WebSocket 代理配置location /api/websocket/eterm {proxy_pass http://111.222.3.4:1111/websocket/eterm;# WebSocket 必须配置proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";proxy_set_header Host $host;# 连接超时设置proxy_read_timeout 86400s;proxy_send_timeout 86400s;proxy_connect_timeout 5s;# 日志记录access_log /var/log/nginx/websocket.log websocket;}
关键字:网站建立时间怎么查_免费的好网站_如何联系百度推广_推广策划方案怎么做

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: