From: Brian Candler Date: 2009-11-29T06:08:22+09:00 Subject: Re: Which server component? > 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. At the moment, you are talking directly over TCP, and your message structure is just JSON objects delimited by newline. 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. - 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. > 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) Look at the examples which come with Rack to see how it works, it's extremely simple. http://rack.rubyforge.org/ -- Posted via http://www.ruby-forum.com/.