Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dunixir
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
teaching
dunixir
Merge requests
!16
Indexes
Code
Review changes
Check out branch
Download
Patches
Plain diff
Closed
Indexes
indexes
into
dev
Overview
0
Commits
13
Pipelines
0
Changes
1
Closed
BENARD Julien
requested to merge
indexes
into
dev
4 years ago
Overview
0
Commits
13
Pipelines
0
Changes
1
Expand
0
0
Merge request reports
Viewing commit
89018464
Prev
Next
Show latest version
1 file
+
21
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
89018464
Some comment about regexp
· 89018464
x18zhan2
authored
4 years ago
websocket/wsclient/lib/client_ws.ex
+
21
−
0
Options
@@ -2,10 +2,31 @@ defmodule ClientWs do
use
WebSockex
def
start
(
_type
,
_args
)
do
@doc
"""
Some codes about checking endpoints' regexp
## Codes begin
# the client will recevie an endpoint from somewhere, we can put this endpoint as default for now
endpoint = "WS2P a0a45ed2 88.174.120.187 20901"
# if this endpoint matches the regexp, we start to connect to duniter
# TODO: there are two types of endpoints, I have only implemented one of them
if String.match?(endpoint, ~r/^WS2P (?:[1-9][0-9]* )?([a-f0-9]{8}) ([a-z_][a-z0-9-_.]*|[0-9.]+|[0-9a-f:]+) ([0-9]+)(?: (.+))?$/) do
[_api, _uuid, host, port] = String.split(endpoint, " ")
url = "ws://#{host}:#{port}"
{:ok,spid} = WebSockex.start_link(url,__MODULE__,:ok)
else
IO.puts "Invalid endpoint#{endpoint}"
end
## Codes end
"""
{
:ok
,
spid
}
=
WebSockex
.
start_link
(
"ws://localhost:4000/ws/chat"
,
__MODULE__
,
:ok
)
WebSockex
.
send_frame
(
spid
,{
:text
,
"hello"
})
{
:ok
,
spid
}
end
def
handle_frame
({
:text
,
text
},
state
)
do
IO
.
inspect
(
text
);
{
:ok
,
state
}
Loading