websocket: move library files to root of module
parent
fa6aaad6df
commit
b28ab2511c
|
@ -1,21 +0,0 @@
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2020 Abdullah Atta
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
|
@ -1,5 +1,7 @@
|
||||||
# WebSockets Library for V
|
# WebSockets Library for V
|
||||||
|
|
||||||
|
Originally located at [thecodrr/vws](https://github.com/thecodrr/vws) (contains example usage)
|
||||||
|
|
||||||
**This is still work-in-progress!**
|
**This is still work-in-progress!**
|
||||||
|
|
||||||
Heavily inspired (and used **very** liberally) from [cwebsockets](https://github.com/jeremyhahn/cwebsocket).
|
Heavily inspired (and used **very** liberally) from [cwebsockets](https://github.com/jeremyhahn/cwebsocket).
|
||||||
|
@ -16,13 +18,3 @@ The websockets library itself is ready and working (passes all tests of AutoBahn
|
||||||
1. SSL (either make the VSChannel work or OpenSSL)
|
1. SSL (either make the VSChannel work or OpenSSL)
|
||||||
|
|
||||||
General code cleanup etc. is also needed.
|
General code cleanup etc. is also needed.
|
||||||
|
|
||||||
## Contributors
|
|
||||||
|
|
||||||
Anyone and everyone is welcome to contribute. I don't have time for working on this completely but I will review and merge Pull Requests ASAP. So if anyone is interested, know that I am interested too.
|
|
||||||
|
|
||||||
If anyone has any questions regarding design etc. please open an Issue or contact me on Discord.
|
|
||||||
|
|
||||||
## Future Planning:
|
|
||||||
|
|
||||||
This is supposed to be merged into V stdlib but it's not ready for that yet. As soon as it is, I will open a PR.
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
module ws
|
module websocket
|
||||||
|
|
||||||
import (
|
import (
|
||||||
eventbus
|
eventbus
|
|
@ -1,7 +1,7 @@
|
||||||
module main
|
module main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
ws
|
net.websocket
|
||||||
eventbus
|
eventbus
|
||||||
time
|
time
|
||||||
readline
|
readline
|
||||||
|
@ -32,17 +32,17 @@ fn main(){
|
||||||
bm.stop()
|
bm.stop()
|
||||||
println( bm.total_message('remarks about the benchmark') )
|
println( bm.total_message('remarks about the benchmark') )
|
||||||
} */
|
} */
|
||||||
mut websocket := ws.new("ws://localhost:9001/getCaseCount")
|
mut ws := websocket.new("ws://localhost:9001/getCaseCount")
|
||||||
//defer { }
|
//defer { }
|
||||||
websocket.subscriber.subscribe("on_open", on_open)
|
ws.subscriber.subscribe("on_open", on_open)
|
||||||
websocket.subscriber.subscribe("on_message", on_message)
|
ws.subscriber.subscribe("on_message", on_message)
|
||||||
websocket.subscriber.subscribe("on_error", on_error)
|
ws.subscriber.subscribe("on_error", on_error)
|
||||||
websocket.subscriber.subscribe("on_close", on_close)
|
ws.subscriber.subscribe("on_close", on_close)
|
||||||
//go
|
//go
|
||||||
websocket.connect()
|
ws.connect()
|
||||||
websocket.read()
|
ws.read()
|
||||||
//time.usleep(2000000)
|
//time.usleep(2000000)
|
||||||
//go websocket.listen()
|
//go ws.listen()
|
||||||
//term.erase_clear()
|
//term.erase_clear()
|
||||||
/* text := read_line("[client]:")
|
/* text := read_line("[client]:")
|
||||||
if text == "close" {
|
if text == "close" {
|
||||||
|
@ -56,7 +56,7 @@ fn main(){
|
||||||
//ws.close(1005, "done")
|
//ws.close(1005, "done")
|
||||||
/*
|
/*
|
||||||
*/
|
*/
|
||||||
//websocket.close(1005, "done")
|
//ws.close(1005, "done")
|
||||||
//read_line("wait")
|
//read_line("wait")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ fn read_line(text string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_open(params eventbus.Params){
|
fn on_open(params eventbus.Params){
|
||||||
println("Websocket opened.")
|
println("websocket opened.")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_message(params eventbus.Params){
|
fn on_message(params eventbus.Params){
|
||||||
|
@ -98,25 +98,25 @@ fn on_message(params eventbus.Params){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_tests(websocket mut ws.Client, num int) {
|
fn start_tests(ws mut ws.Client, num int) {
|
||||||
for i := 1; i < num; i++ {
|
for i := 1; i < num; i++ {
|
||||||
println("Running test: " + i.str())
|
println("Running test: " + i.str())
|
||||||
websocket.uri = "ws://localhost:9001/runCase?case=${i.str()}&agent=vws/1.0a"
|
ws.uri = "ws://localhost:9001/runCase?case=${i.str()}&agent=vws/1.0a"
|
||||||
if websocket.connect() >= 0 {
|
if ws.connect() >= 0 {
|
||||||
websocket.listen()
|
ws.listen()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println("Done!")
|
println("Done!")
|
||||||
websocket.uri = "ws://localhost:9001/updateReports?agent=vws/1.0a"
|
ws.uri = "ws://localhost:9001/updateReports?agent=vws/1.0a"
|
||||||
if websocket.connect() >= 0 {
|
if ws.connect() >= 0 {
|
||||||
websocket.read()
|
ws.read()
|
||||||
websocket.close(1000, "disconnecting...")
|
ws.close(1000, "disconnecting...")
|
||||||
}
|
}
|
||||||
exit(0)
|
exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_close(params eventbus.Params){
|
fn on_close(params eventbus.Params){
|
||||||
println("Websocket closed.")
|
println("websocket closed.")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_error(params eventbus.Params){
|
fn on_error(params eventbus.Params){
|
|
@ -1,4 +1,4 @@
|
||||||
module ws
|
module websocket
|
||||||
|
|
||||||
fn (ws mut Client) read_handshake(seckey string){
|
fn (ws mut Client) read_handshake(seckey string){
|
||||||
l.d("reading handshake...")
|
l.d("reading handshake...")
|
|
@ -1,4 +1,4 @@
|
||||||
module ws
|
module websocket
|
||||||
|
|
||||||
fn C.write() int
|
fn C.write() int
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
module ws
|
module websocket
|
||||||
|
|
||||||
#flag -lssl
|
#flag -lssl
|
||||||
#include <openssl/rand.h>
|
#include <openssl/rand.h>
|
|
@ -1,4 +1,4 @@
|
||||||
module ws
|
module websocket
|
||||||
|
|
||||||
pub fn utf8_validate_str(str string) bool {
|
pub fn utf8_validate_str(str string) bool {
|
||||||
return utf8_validate(str.str, str.len)
|
return utf8_validate(str.str, str.len)
|
|
@ -1,4 +1,4 @@
|
||||||
module ws
|
module websocket
|
||||||
|
|
||||||
import (
|
import (
|
||||||
time
|
time
|
|
@ -1,4 +1,4 @@
|
||||||
module ws
|
module websocket
|
||||||
|
|
||||||
import (
|
import (
|
||||||
net
|
net
|
Loading…
Reference in New Issue