wren-cli icon indicating copy to clipboard operation
wren-cli copied to clipboard

Using Libuv to create a socket server

Open masoodahm opened this issue 8 years ago • 8 comments

hi, Since wren uses libuv, is there a way for wren to use underlying libuv's network IO functions, maybe via io module, I haven't found any thing in the docs regarding the wren built in io module. It says it's up to the host application to provide interfaces, but what about using wren script as a stand alone application. Also I am coming from web development background, as opposed to game dev. It would really be cool to be able to write a web framework using wren

masoodahm avatar Jan 07 '17 15:01 masoodahm

libuv is only used in the CLI, wren itself doesn't know anything. You could build up on the CLI or doing something similar from scratch.

minirop avatar Jan 07 '17 20:01 minirop

ok I will try that

masoodahm avatar Jan 08 '17 09:01 masoodahm

The short answer is no, the Wren CLI doesn't currently expose libuv's networking API. I intend to, I just haven't gotten there yet.

munificent avatar Mar 26 '18 15:03 munificent

OMG, a simple MUD or something in Wren would be pretty awesome.

joshgoebel avatar Apr 26 '21 08:04 joshgoebel

Disclaimer: I'm new to Wren and it's embedding and C++ is not my best language, and low-level networking is not the simplest... so go easy on me. But if anyone had comments or wanted to try it out, test it, etc... there is no outbound connections, this is just a TCP server that handles incoming connections.

There is probably all sorts of ugly, missing error handling, and really there should probably be hooks for disconnect, etc... This should be considered like an alpha version.

https://github.com/joshgoebel/wren-cli/tree/network

A simple echo server:

import "socket" for TCPServer

var server = TCPServer.new("127.0.0.1",7000)
server.onConnect = Fn.new() { |conn|
    conn.writeLn("Hello, user.")
    var x 
    while (x = conn.readWait()) {
        conn.write(x)
    }
}
server.serve()

Very open to a high level discussion of what primitives we need to flesh this out.

joshgoebel avatar Apr 28 '21 07:04 joshgoebel

This seems not to be in your repository @joshgoebel. Might it be in a branch you have not committed to github yet?

aosenkidu avatar Feb 06 '23 01:02 aosenkidu

https://github.com/joshgoebel/wren-console/blob/network/src/module/network.wren

The stuff I was working on can be found in the branch I pointed to.

joshgoebel avatar Feb 12 '23 03:02 joshgoebel

https://github.com/joshgoebel/wren-console/blob/network/src/module/network.wren

The stuff I was working on can be found in the branch I pointed to.

Thank you :D however, the link I answered to: is either a different repository or a different branch. So no reason to "down thumb" a valid question.

Perhaps I just don't grasp the github webinterface ...

aosenkidu avatar Feb 24 '23 12:02 aosenkidu