From: Tim Bennen Date: 2009-11-29T07:36:09+09:00 Subject: Re: Which server component? Thank you very much for your reply! Brian Candler wrote: >> The clients send the messages to the server witch JSON via a persistent >> TCP connection (it must be persistent). The server (ruby scripts) >> receive the messages and send a JSON answer string back to the client. >> >> My ruby tcp server is build up with this snippet of source code: >> http://segment7.net/projects/ruby/snippets/server.rb >> >> Now I like to run it on port 80/443 as a webservice, because the tcp >> server is not so scalable and I do not have any idea how to run it >> secure via ssl/tls. > > You are talking about two different things. Webservers talk HTTP(S). You > can have a persistent HTTP connection, but the messages sent over it > would be HTTP requests and responses. Okay, I understand what you mean. > At the moment, you are talking directly over TCP, and your message > structure is just JSON objects delimited by newline. Right. > So really you have two options: > > - scale your existing protocol. You could make it work very efficiently > with thousands of concurrent connections using 'eventmachine' or one of > the other reactor-pattern libraries. Adding SSL to your existing code is > also pretty easy. If I would use EventMachine, how would be the architecture? EventMachine receives the messages and forward it to my ruby scripts? But EventMachine would replace my TCP server? And with EventMachine it is easy to set up a persistent SSL connection? > - or you switch entirely to a new protocol, which would be JSON over > HTTP(S). This is more heavyweight (higher overhead), but does give you a > large number of scaling options and is arguably more 'standard' than > your existing custom protocol. Okay. >> Should I use an apache webserver mit Phusion Passenger or there are >> better ways that the server could make persistent tcp connections with >> security (SSL) to send/receive JSON messages? > > As this is a very small service and you want it to run as fast as > possible, I suggest you write it as a Rack application. There are then > lots of different ways you can actually run your Rack application (under > Phusion Passenger is just one of them) Okay, I could build up an apache webserver with for example phusion passenger which enables the ssl security and the persistent connection. And then I use Rack to get the requests and I can send the responses back to the client. Is that right? But how do I call the server from the client? Is it a POST HTTP Request with the JSON message in his body? > Look at the examples which come with Rack to see how it works, it's > extremely simple. > http://rack.rubyforge.org/ Ruby on Rails did also use this? I have to read a little bit... Thanks a lot! -- Posted via http://www.ruby-forum.com/.