isobit / ws-tcp-relay Goto Github PK
View Code? Open in Web Editor NEWA simple relay between WebSocket clients and TCP servers
License: MIT License
A simple relay between WebSocket clients and TCP servers
License: MIT License
Hi,
-p 1515
run and Listening port 4223?
Have a good day.
This would make a really good higher performance alternative to Websockify since their C implementation is not quite developed and suffers from security issues.
Currently only the Websocket side supports TLS (through the -tlscert
and -tlskey
options). Support should be added for TLS on the TCP side.
This could be done by adding a flag (e.g. -tcptls
or -tls
) which causes ws-tcp-relay
to use crypto/tls
to dial the connection instead of net
. Additional options may need to be added for configuring the connection (see https://golang.org/pkg/crypto/tls/#Config), such as specifying the root CAs.
Care should be taken to avoid confusion between client-side (TCP) and server-side (WSS) TLS. This may mean renaming the -tlscert
and -tlskey
options, although the old ones should be retained for backwards-compat.
Proposed new usage:
Usage: ws-tcp-relay <tcpTargetAddress>
-b Use binary frames instead of text frames
-binary
Use binary frames instead of text frames
-p uint
The port to listen on (default 4223)
-port uint
The port to listen on (default 4223)
-wsscert string (also -tlscert)
Path to a certificate (PEM file) to use for serving WebSockets using TLS. If the certificate is signed by
a certificate authority, the file should be the concatenation of the server's certificate, any
intermediates, and the CA's certificate. Must also specify -wsskey.
-wsskey string (also -tlskey)
Path to a private key (PEM file) to use for serving WebSockets using TLS. Must also specify -wsscert.
-tcptls
Use TLS for outgoing TCP connections
-tcptlscert
Path (or multiple paths) to a certificate (PEM file) to use for outgoing TCP connections using TLS.
May be specified multiple times Only used when -tcptls is specified.
-tcptlsrootcert
TODO
How do I approach securing the connection to the ws-tcp-relay ?
I have a web app (react) that needs to connect the ws-tcp-relay but i dont want any old person on the internet to access the websocket
Darwin x86 on M1
(run via: arch -x86_64 ./ws-tcp-relay -p 4222 nats.messaging:4222
)
Process: ws-tcp-relay [21401]
Path: /Users/USER/*/ws-tcp-relay
Identifier: ws-tcp-relay
Version: ???
Code Type: X86-64 (Translated)
Parent Process: zsh [19543]
Responsible: iTerm2 [535]
User ID: 502
Date/Time: 2021-04-12 15:05:39.982 -0400
OS Version: macOS 11.2.3 (20D91)
Report Version: 12
Anonymous UUID: DDCA91AB-B8CA-98E1-CCD5-DFD5664B2528
Time Awake Since Boot: 82000 seconds
System Integrity Protection: enabled
Crashed Thread: 0
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000018
Exception Note: EXC_CORPSE_NOTIFY
Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [21401]
VM Regions Near 0x18:
-->
__TEXT 1000000-1413000 [ 4172K] r-x/rwx SM=COW /Users/*
Application Specific Information:
dyld2 mode
Thread 0 Crashed:
0 runtime 0x00007ffdffed0bb0 0x7ffdffebf000 + 72624
1 ws-tcp-relay 0x00000000010579cd runtime.bsdthread_register + 29 (sys_darwin_amd64.s:392)
2 ws-tcp-relay 0x000000000102bfb1 runtime.schedinit + 161 (proc.go:482)
Thread 1:: com.apple.rosetta.exceptionserver
0 runtime 0x00007ffdffec1238 0x7ffdffebf000 + 8760
1 runtime 0x00007ffdffecb354 0x7ffdffebf000 + 50004
2 runtime 0x00007ffdffecc1f8 0x7ffdffebf000 + 53752
Thread 0 crashed with ARM Thread State (64-bit):
x0: 0x800000010000fb90 x1: 0x0000000001057970 x2: 0x0000000000000000 x3: 0x0000000000000000
x4: 0x0000000000000000 x5: 0x0000000000000000 x6: 0x0000000000000000 x7: 0x000000c42000e000
x8: 0x00007ffdfff34a00 x9: 0x00007ffdfff34a08 x10: 0x0000000000000000 x11: 0x0000000000000080
x12: 0x0055555555555555 x13: 0x00000000000000f5 x14: 0x0000000000000075 x15: 0x0000000000000028
x16: 0x000000000000016e x17: 0x0000000000000000 x18: 0x800000010000fb90 x19: 0x0000000100000000
x20: 0x00000000000007ff x21: 0x0000000100014fc0 x22: 0x00000002058bbbf8 x23: 0x00000000018ad224
x24: 0x0000000001026e60 x25: 0x00000000015041ec x26: 0x00000000014f9ad4 x27: 0x0000000000000000
x28: 0x00000000010579cd fp: 0x00007ffdffed0b98 lr: 0x00000000018ad254
sp: 0x000000010000fb90 pc: 0x00007ffdffed0bb0 cpsr: 0x80000000
far: 0x0000000000000018 esr: 0x92000006
Binary Images:
0x1000000 - 0x1412fff +ws-tcp-relay (???) /Users/USER/*/ws-tcp-relay
0x1017a5000 - 0x101840fff dyld (832.7.3) <0D4EA85F-7E30-338B-9215-314A5A5539B6> /usr/lib/dyld
0x7ffdffebf000 - 0x7ffdfff32fff +runtime (203.30) <C98E75A6-BDC8-3D5C-B95B-6422005E96D8> /Library/Apple/*/runtime
External Modification Summary:
Calls made by other processes targeting this process:
task_for_pid: 0
thread_create: 0
thread_set_state: 0
Calls made by this process:
task_for_pid: 0
thread_create: 0
thread_set_state: 0
Calls made by all processes on this machine:
task_for_pid: 8534930
thread_create: 0
thread_set_state: 0
VM Region Summary:
ReadOnly portion of Libraries: Total=5860K resident=0K(0%) swapped_out_or_unallocated=5860K(100%)
Writable regions: Total=150.7M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=150.7M(100%)
VIRTUAL REGION
REGION TYPE SIZE COUNT (non-coalesced)
=========== ======= =======
Rosetta Arena 2048K 1
Rosetta Generic 584K 143
Rosetta IndirectBranch 32K 1
Rosetta JIT 128.0M 1
Rosetta Return Stack 20K 2
Rosetta Thread Context 20K 2
VM_ALLOCATE 528.5G 9
VM_ALLOCATE (reserved) 8K 2 reserved VM address space (unallocated)
__DATA 640K 6
__DATA_CONST 32K 1
__LINKEDIT 636K 5
__TEXT 5260K 3
mapped file 4.7G 12
=========== ======= =======
TOTAL 533.3G 188
TOTAL, minus reserved VM space 533.3G 188
Darwin amd64
Process: ws-tcp-relay_darwin_amd64 [21270]
Path: /Users/USER/*/ws-tcp-relay_darwin_amd64
Identifier: ws-tcp-relay_darwin_amd64
Version: ???
Code Type: X86-64 (Translated)
Parent Process: zsh [19543]
Responsible: iTerm2 [535]
User ID: 502
Date/Time: 2021-04-12 14:58:42.889 -0400
OS Version: macOS 11.2.3 (20D91)
Report Version: 12
Anonymous UUID: DDCA91AB-B8CA-98E1-CCD5-DFD5664B2528
Time Awake Since Boot: 82000 seconds
System Integrity Protection: enabled
Crashed Thread: 0
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000018
Exception Note: EXC_CORPSE_NOTIFY
Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [21270]
VM Regions Near 0x18:
-->
__TEXT 1000000-1413000 [ 4172K] r-x/rwx SM=COW /Users/*
Application Specific Information:
dyld2 mode
Thread 0 Crashed:
0 runtime 0x00007ffdffe99bb0 0x7ffdffe88000 + 72624
1 ws-tcp-relay_darwin_amd64 0x00000000010579cd runtime.bsdthread_register + 29 (sys_darwin_amd64.s:392)
2 ws-tcp-relay_darwin_amd64 0x000000000102bfb1 runtime.schedinit + 161 (proc.go:482)
Thread 1:: com.apple.rosetta.exceptionserver
0 runtime 0x00007ffdffe8a238 0x7ffdffe88000 + 8760
1 runtime 0x00007ffdffe94354 0x7ffdffe88000 + 50004
2 runtime 0x00007ffdffe951f8 0x7ffdffe88000 + 53752
Thread 0 crashed with unknown flavor: 7, state_count: 4
Binary Images:
0x1000000 - 0x1412fff +ws-tcp-relay_darwin_amd64 (???) /Users/USER/*/ws-tcp-relay_darwin_amd64
0x1016ba000 - 0x101755fff dyld (832.7.3) <0D4EA85F-7E30-338B-9215-314A5A5539B6> /usr/lib/dyld
0x7ffdffe88000 - 0x7ffdffefbfff +runtime (203.30) <C98E75A6-BDC8-3D5C-B95B-6422005E96D8> /Library/Apple/*/runtime
External Modification Summary:
Calls made by other processes targeting this process:
task_for_pid: 0
thread_create: 0
thread_set_state: 0
Calls made by this process:
task_for_pid: 0
thread_create: 0
thread_set_state: 0
Calls made by all processes on this machine:
task_for_pid: 8479265
thread_create: 0
thread_set_state: 0
VM Region Summary:
ReadOnly portion of Libraries: Total=5860K resident=0K(0%) swapped_out_or_unallocated=5860K(100%)
Writable regions: Total=150.7M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=150.7M(100%)
VIRTUAL REGION
REGION TYPE SIZE COUNT (non-coalesced)
=========== ======= =======
Rosetta Arena 2048K 1
Rosetta Generic 584K 143
Rosetta IndirectBranch 32K 1
Rosetta JIT 128.0M 1
Rosetta Return Stack 20K 2
Rosetta Thread Context 20K 2
VM_ALLOCATE 528.5G 9
VM_ALLOCATE (reserved) 8K 2 reserved VM address space (unallocated)
__DATA 640K 6
__DATA_CONST 32K 1
__LINKEDIT 636K 5
__TEXT 5260K 3
mapped file 4.7G 12
=========== ======= =======
TOTAL 533.3G 188
TOTAL, minus reserved VM space 533.3G 188
Sending binary data returns client error (chrome) "WebSocket connection to 'ws://127.0.0.1:8008' failed: Could not decode a text frame as UTF-8." How can i force relay to use binary websocket frames?
I have been testing the combination of ws-tcp-relay
and websocket-nats
using a simple web client.
In my particular scenario, I'm using Docker to launch several ws-tcp-relay
instances and connect them to a single NATS server. Then, I have a webapp that uses websocket-nats
to connect to a ws-tcp-relay
instance randomly and open a websocket session.
I have some general questions about ws-tcp-relay
and I'm wondering if you can share some insight.
do you have any info on how many connections a single ws-tcp-relay
instance can handle?
at what point does ws-tcp-relay
relays the NATS connection?, when a client first connects to the relay? [via nats.connect('ws://localhost:4223')
] or when the client first subscribes to a NATS topic?
does ws-tcp-relay
keeps the relay session to NATS alive? or is this the responsibility of the client using websocket-nats
?
I'm interested in evaluating the scalability of ws-tcp-relay
in combination with websocket-nats
and I'm wondering if you might have any suggestions or feedback.
Thanks,
A.
Could you provide an example how to use this tool? Let's assume that I'm having a websocket connection already initialized and it is running on port 5000. Relying on the code I assume that it should create a tcp connection on the specified tcp address and should look at the websocket connection specified with the -p
flag. My expectation is to receive the values (for example using netcat
(nc
) sent over the websocket to be consumable over tcp, in other words to receive the values from the websocket connection. But unfortunately is not happening.
Thanks for writing a useful tool! I've run into this: https://go-review.googlesource.com/c/go/+/9399 and I think it may be a good idea if you use io.CopyBuffer() to improve the relaying performance.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.