This patch adds ch_listen() function to Vim, allowing scripts to create listening sockets and accept incoming network connections. This enables Vim to act as a simple network server for various use cases.
ch_listen(address [, options]) - Listen on a socket and accept connections
channel_listen_unix(path, callback) - Unix domain socket support
channel_listen_func(argvars) - Vim script interface
ch_listen field to struct channel_S to mark listening socketschannel_read() to handle accept() on listening socketsfunction! OnConnect(channel, address) echomsg 'Client connected from: ' . a:address call ch_setoptions(a:channel, { \ 'callback': function('OnData'), \ }) endfunction function! OnData(channel, data) echomsg 'Received: ' . a:data endfunction let server = ch_listen('127.0.0.1:8080', { \ 'callback': function('OnConnect'), \ })
Test_listen() in test_channel.vimThis complements the existing ch_open() function:
ch_open() - connect to a serverch_listen() - accept connections as a serverThis is demonstration of HTTP server written in Vim script.
image.png (view on web)https://github.com/vim/vim/pull/19231
(7 files)
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
I'll fix test fail in later.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
@mattn pushed 1 commit.
—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Thanks that is nice. But I'll move this after the Vim 9.2 release.
Can a few people try it out? I'd also think that we should have a very simple practical example for this in the help.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
It is not clear from the docs how ch_listen() differs from ch_open({address} [, {options}])? See :h channel-address for possible values of address.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
@chrisbra This is simple practice example working as HTTP file server.
https://gist.github.com/mattn/3e691419c37fe7ce501dc37e2a1bb545
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()