thanks!
i understand the REPL quirks, this is something about the header itself i think (?). nodejs websockets explicitly support nanomsg BUS subprotocol, but these other libraries don’t appear to.
i’m not sure i care enough about this to investigate further myself, but would be curious if anyone has an easy answer. here’s what i tried:
python3
import asyncio
import websockets
import sys
msg = "print('hello')\n"
ip = "norns.local"
port = "5555"
argc = len(sys.argv)
if argc > 1: msg = sys.argv[1]
if argc > 2: ip = sys.argv[2]
if argc > 3: port = sys.argv[3]
async def tx():
uri = "ws://{}:{}/".format(ip, port)
print ("sending message '{}' to server {}".format(msg, uri))
print("connecting...")
async with websockets.connect(uri) as websocket:
print("...connected.")
await websocket.send(msg)
response = await websocket.recv()
print(response)
asyncio.get_event_loop().run_until_complete(tx())
dartlang
import 'dart:io';
void main(List<String> args) async {
var msg = 'print("hello")\n';
var ip = '192.168.42.23';
var port = '5555';
if (args.length > 0) { msg = args[0]; }
if (args.length > 1) { ip = args[1]; }
if (args.length > 2) { port = args[2]; }
var uri = "ws://$ip:$port/";
print("connecting to $uri ...");
var webSocket = await WebSocket.connect(uri);
print("..done.");
if (webSocket != null && webSocket.readyState == WebSocket.OPEN) {
webSocket.add(msg);
} else {
print('WebSocket not connected, message $msg not sent');
}
}
both programs hang on “connecting…”. if i halt execution i see the python script stuck in some HTTP header parsing. thats as far as i’ve gone. my third try was nodejs, which of course works fine and is used in maiden. (it just seems like an onerous dependency for a CLI tool.)
also: we don’t need to be using nanomsg at all. it was an expedient choice in the early days of the project, before websockets were even decided on as the REPL transport layer. but if there’s a better option i’ve no problem swapping it out.