我想为基于windows的桌面应用程序提供一个web接口,反之亦然。我的桌面应用程序是用wxRuby编写的,and服务器是Sinatra (使用webrick)。最简单的想法就是把它们混在一起,这是行不通的。
此代码不起作用。webserver和gui应用程序不能同时运行。桌面应用程序首先运行,然后关闭;sinatra启动。
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再来一次。桌面应用程序一直运行到关闭,然后then服务器启动。所以我试着用丝线启动辛纳特拉。
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再来一次。桌面应用程序一直运行到关闭,然后then服务器启动。
请提出建议,但请记住,我真的很想有一个过程。如果您的解决方案是两个进程,则为;我希望强大的进程间通信不需要轮询。。
谢谢!杰夫
发布于 2010-01-19 05:17:52
这至少会启动,不确定这是否违反了一些线程规则。
require 'win32/process'
require 'sinatra/base'
class MyWebServer < Sinatra::Base
get '/' do
'Hello world!'
end
end
Thread.new do
MyWebServer.run! :host => 'localhost', :port => 4567
end
require 'wx'
class MyGui < Wx::App
def on_init
t = Wx::Timer.new(self, 55)
evt_timer(55) { Thread.pass }
t.start(1)
evt_idle { Thread.pass }
@frame = Wx::Frame.new( nil, -1, "Application" )
@frame.show
true
end
end
app = MyGui.new
app.main_loop发布于 2011-02-28 17:22:13
您可以使用鲍林,但我还没有使用它。
https://stackoverflow.com/questions/2087390
复制相似问题