Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
test_webhook
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
时海鑫
test_webhook
Commits
a3353e10
Commit
a3353e10
authored
Oct 09, 2025
by
时海鑫
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test1
parent
52000fbc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
0 deletions
+44
-0
WSClint.py
WSClint.py
+23
-0
WSSerivce.py
WSSerivce.py
+21
-0
No files found.
WSClint.py
0 → 100644
View file @
a3353e10
import
websocket
# 连接成功时的回调函数
def
on_open
(
ws
):
print
(
"WebSocket连接已建立"
)
ws
.
send
(
"Hello, WebSocket!"
)
# 发送消息
# 接收到服务器消息时的回调函数
def
on_message
(
ws
,
message
):
print
(
"收到来自服务器的消息:{}"
.
format
(
message
))
# 关闭连接时的回调函数
def
on_close
(
ws
):
print
(
"WebSocket连接已断开"
)
# 创建WebSocket客户端实例,并注册回调函数
ws
=
websocket
.
WebSocketApp
(
"ws://localhost:6677/"
,
# WebSocket服务器地址
on_open
=
on_open
,
# 连接成功时的回调函数
on_message
=
on_message
,
# 接收到消息时的回调函数
on_close
=
on_close
)
# 关闭连接时的回调函数
# 运行WebSocket客户端
ws
.
run_forever
()
\ No newline at end of file
WSSerivce.py
0 → 100644
View file @
a3353e10
from
websocket_server
import
WebsocketServer
# 接收到客户端连接时触发
def
new_client
(
client
,
server
):
print
(
"新的客户端连接:{}"
.
format
(
client
[
'address'
]))
# 接收到客户端消息时触发
def
message_received
(
client
,
server
,
message
):
print
(
"收到来自{}的消息:{}"
.
format
(
client
[
'address'
],
message
))
print
(
"lovesosoi"
)
server
.
send_message
(
client
,
"server 收到消息:{}"
.
format
(
message
))
# 回复消息给客户端
PORT
=
8222
# 服务器端口
server
=
WebsocketServer
(
host
=
'0.0.0.0'
,
port
=
PORT
)
# 创建WebSocket服务器
print
(
"服务器已经开启"
)
server
.
set_fn_new_client
(
new_client
)
# 注册新客户端连接事件处理方法
server
.
set_fn_message_received
(
message_received
)
# 注册消息接收事件处理方法
server
.
run_forever
()
# 运行WebSocket服务器
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment