在桌面应用程序中嵌入网络服务器:wxRuby 和 Sinatra
我很乐意为我的基于 Windows 的桌面应用程序提供一个 Web 界面,反之亦然。我的桌面应用程序是用 wxRuby 编写的,网络服务器是 Sinatra(使用 webrick)。最简单的想法就是把它们混在一起,这是行不通的。
这段代码不起作用。网络服务器和 GUI 应用程序不同时运行。桌面应用程序先运行,关闭后再运行;西纳特拉启动。
require 'wx'
require 'sinatra'
configure do set :server, 'webrick' end
get '/' do
"Sinatra says hello"
end
class MyApp < Wx::App
def on_init
@frame = Wx::Frame.new( nil, -1, "Application" )
@frame.show
end
end
app = MyApp.new
app.main_loop
所以我想把最后两行改为
Thread.new do
app = MyApp.new
app.main_loop
end
Again。桌面应用程序运行直至关闭,然后网络服务器启动。所以我尝试在线程中启动 Sinatra。
Thread.new do
require 'sinatra'
configure do set :server, 'webrick' end
get '/' do
"Sinatra says hello"
end
end
require 'wx'
class MyApp < Wx::App
def on_init
@frame = Wx::Frame.new( nil, -1, "Application" )
@frame.show
end
end
app = MyApp.new
app.main_loop
再次。桌面应用程序运行直至关闭,然后网络服务器启动。
请提出建议,但请记住,我真的很想只有一个过程。 如果您的解决方案是两个进程;我想要不需要轮询的强大的进程间通信。
谢谢! 杰夫
I would love to give my windows based desktop applications a web interface and vice versa. My desktop application is written in wxRuby and the webserver is Sinatra (using webrick). The simplest idea was just to mash them together, this does not work.
This code does not work. The webserver and gui app do not run simultaneously. The desktop application runs first, and then after it is closed; sinatra starts.
require 'wx'
require 'sinatra'
configure do set :server, 'webrick' end
get '/' do
"Sinatra says hello"
end
class MyApp < Wx::App
def on_init
@frame = Wx::Frame.new( nil, -1, "Application" )
@frame.show
end
end
app = MyApp.new
app.main_loop
So I thought about changing the last two lines to
Thread.new do
app = MyApp.new
app.main_loop
end
Again. Desktop App runs until closed, then webserver starts. So I tried starting Sinatra in a Thread.
Thread.new do
require 'sinatra'
configure do set :server, 'webrick' end
get '/' do
"Sinatra says hello"
end
end
require 'wx'
class MyApp < Wx::App
def on_init
@frame = Wx::Frame.new( nil, -1, "Application" )
@frame.show
end
end
app = MyApp.new
app.main_loop
Again. Desktop App runs until closed, then webserver starts.
Please advise, but keep in mind that I would really like to just have one process. If your solution is two processes; I would like strong inter-process communication that does not require polling.
Thanks!
Jeff
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这至少会启动,不确定这是否违反了一些线程规则。
This at least starts up, not sure if this breaks some threading rules.
你可以使用 bowline,但我还没有使用它。
you can use bowline, but i'm not yet using it.