在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:dandeliondeathray/DandelionWebSockets.jl开源软件地址:https://github.com/dandeliondeathray/DandelionWebSockets.jl开源编程语言:Julia 82.8%开源软件介绍:DandelionWebSocketsDandelionWebSockets is a client side WebSocket package. UsageCreate a subtype of using DandelionWebSockets
import DandelionWebSockets: on_text, on_binary
import DandelionWebSockets: state_connecting, state_open,
state_closing, state_closed
mutable struct MyHandler <: WebSocketHandler
# The connection is only available once `state_connecting` has been called.
connection::Union{WebSocketConnection, Nothing}
end
# These are called when you get a text or binary frame, respectively.
on_text(handler::MyHandler, text::String) = ...
on_binary(handler::MyHandler, data::Vector{UInt8}) = ...
# These are called when the state of the WebSocket changes.
state_connecting(handler::MyHandler, connection::WebSocketConnection) = ...
state_open(handler::MyHandler) = ...
state_closing(handler::MyHandler) = ...
state_closed(handler::MyHandler) = ... The following functions are available on send_text(c::WebSocketConnection, s::String)
send_binary(c::WebSocketConnection, data::Vector{UInt8})
# Close the WebSocket.
stop(c::WebSocketConnection)
# Send a multi-frame text message
textsender = sendmultiframetext(connection)
sendframe(textsender, "Hello")
sendframe(textsender, "world")
sendframe(textsender, "Goodbye."; isfinal=true)
# Send a multi-frame binary message
binarysender = sendmultiframebinary(connection)
sendframe(binarysender, b"Hello")
sendframe(binarysender, b"world")
sendframe(binarysender, b"Goodbye."; isfinal=true) To connect to a WebSocket server, call
For the full example code, please check out Interface changesAlongside (but unrelated to) the update to Julia 0.7/1.0, the interface has changed some.
Instead of using the So, in short, change struct MyHandler <: WebSocketHandler
client::WSClient
end
state_connecting(::MyHandler) = ... to mutable struct MyHandler <: WebSocketHandler
connection::Union{WebSocketConnection, Nothing}
end
state_connecting(handler::MyHandler, connection::WebSocketConnection) = handler.connection = connection The sending methods all take a Note on I/O and thread safetyNote that print and I/O functions are not thread safe in Julia. Using them in the message and state callbacks (as is currently done in the examples) may lead to unexpected behaviour, or crashes. See JuliaLang/julia#17388 for more details. Thank you to @alessandrousseglioviretta for bringing up this issue. Note on SSLAt the moment, SSL is not functioning, due to moving from Requests.jl to HTTP.jl. This is presumably just a matter of fixing a minor issue, as HTTP.jl does have SSL support. Releases and JuliaThis package is now registered with Julias package manager. Please only use version 0.1.1 and higher. Version 0.1.0 contains three serious bugs, which were fixed for 0.1.1. Julia 0.7/1.0Migration to Julia 1.0 is nearly complete. A new release will be available soon. Before the migration is complete, there is a PR to an upstream package that must be accepted, or I must configure the dependencies to use a patched version instead of the latest release. ContributorsThese brave people have contributed to this package:
LicenseDandelionWebSockets is licensed under the MIT license. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论