Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Events
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
JavaDevTeam
notes
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
notes
/
Websocket
/
websocket-征途.java
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
37 lines (26 loc) · 1.07 KB
master
Breadcrumbs
notes
/
Websocket
/
websocket-征途.java
Copy path
Top
File metadata and controls
Code
Blame
37 lines (26 loc) · 1.07 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#
对象编解码
*
Encoder
*
Decoder
*
生命周期
*
服务器启动的时候创建实例
*
每个连接仅仅会创建一个实例
*
在第一次连接的时候执行
init
,
在连接关闭的时候执行
destroy
#
消息处理器个数
*
一个Endpoint
在注解式中对应类型的
message
(
二进制
/
文本
/
pong
),
只能有一个
@
OnMessage
出现
*
一个Endpoint
在编程式中对应类型的
message
(
二进制
/
文本
/
pong
),
只能有一个
MessageHandler出现
(
MesssageHandler
,
addMessageHandler
(
MessageHandler
handler
));
#
WebSocket
消息通信和线程
*
每一个新的连接
,
都会创建新的
Endpoint
实例
*
每个WebSocket端点实例
,
在任意时刻都只能被一个线程调用
*
当消息问分片形式到达的时候
,
WebSocket
API
会保证以正确的顺序调用相应的端点
,
并且消息不会与其他的消息紊乱
#
重要的API
*
ServerEndpointConfig
ServerEndpointConfig
.
Configurator
#
Session
#
消息高级处理
*
ping
/
pong
*
同步消息
/
异步消息
*
消息批处理
#
获取HTTP组件
*
自定义
ServerEndpointConfig
.
Configurator
类
,
覆写方法
:
modifyHandshake
*
调用形参
:
HandshakeRequest
的API
HttpSession
getHttpSession
();
来获取到HTTP
,
Session
*
往该Session里面添加的对象
,
最好都去实现监听器
,
这样的话
,
当Session失效
,
就可以通过监听器通知到WebSocket
You can’t perform that action at this time.