Please help me to creating model of server

I need TCPServer, who should:
1) accept and maintain a connection of clients
2) send to client response for their requests
3) send to client responses from redis database

I don't know how to correct do this.

If i do something like this:
Thread.start(server.accept) do |client|
  Thread.new do
    # get requests
  end

  Thread.new do
    # send responses
  end
end

I have 3 threads for each client..

Maybe is possible to solve a problem without a threads or use global
threads (not for each client).

···

--
Posted via http://www.ruby-forum.com/.

Without getting too far into the details of what your server is going to do,
take a look at the GServer class -
http://www.ruby-doc.org/stdlib/libdoc/gserver/rdoc/index.html\.

···

On Thu, Feb 17, 2011 at 6:57 PM, Yan Bernacki <releu@me.com> wrote:

I need TCPServer, who should:
1) accept and maintain a connection of clients
2) send to client response for their requests
3) send to client responses from redis database

I don't know how to correct do this.

If i do something like this:
Thread.start(server.accept) do |client|
Thread.new do
   # get requests
end

Thread.new do
   # send responses
end
end

I have 3 threads for each client..

Maybe is possible to solve a problem without a threads or use global
threads (not for each client).

--
Posted via http://www.ruby-forum.com/\.

I need TCPServer, who should:

As Chris said below, you need GServer :slight_smile:

1) accept and maintain a connection of clients
2) send to client response for their requests
3) send to client responses from redis database

require 'gserver'
class YourServer < GServer
  def serve( io )
    # ... io is an IO object that can be read/written
  end
end

server = YourServer.new( YOUR_PORT )
server.audit = true # turn on debugging output
server.start ; server.join

···

On Thu, Feb 17, 2011 at 9:57 AM, Yan Bernacki <releu@me.com> wrote:

Thanks! :slight_smile:

···

--
Posted via http://www.ruby-forum.com/.