Re: Multithreaded and/or nonblocking server?



On 16 Feb 2006 15:51:22 -0800, macapone@xxxxxxxxx wrote:

Hi Folks,

I'm trying to write a TCP server that will process and respond to
client XML queries. Nothing new there, plenty of examples on the web.
But here's the catch...

When a client connects, the connection is persistent, similar to a chat
server. the client "chats" a request and gets a response, chats
another request, etc. However, some requests are long-running, and
while waiting for a response to request #1, the client should be able
to send requests #2 and #3 and get responses (without having to open a
new connection to the server).

The only way to do this is to either fork or thread the request
processing code on the server.

Right now I'm using Net::Daemon as my server, although I'm certainly
open to alternatives. I've also looked at POE and a few other modules
out there. Basically, I need my handle_request() function to somehow
asynchronously process the request and then communicate the result back
to the client (via event handler? signal? fork? not sure...) when it
has finished processing. It seems as though all the examples out there
are geared towards forking/spawing/etc when a connection is made, and
closing that connection when finished. But I'm looking to keep the
connection open and be able to send requests and get responses
asynchronously.

I'm hoping someone out there has done this and can point me in the
right direction. Any thoughts?

Thanks in advance!
MAC

You have said alot there. I havent used Net::Daemon (Unix service?).
Are you writing the cline and server?

I don't know about Perl but the server side on a Win32 platform
a simple server model goes something like this:

A single, usually non-threaded routine waits for connect
requests. Upon connect, the user info, ip, etc.. info is recorded into
an array. Then a service thread (the same function every time) is started
to handle just the requests from that client. When the client disconnects,
ahhh, the record of his connect data is expunged.

This happens via many syncronization layers, depending on how complex a
model.

To write the client is trivial.
The general server thread CAN however (if the connect routine is threaded and
queued) host multiple requests from the same ip, etc.. however it complicates
things, but is still trivial.

Doing this in Perl is laughable since it puts the onus on a fixed design dll
w32 layer to be expanded, having to matriculate through the perl interfaces.
Not something likely. Generality at best is what you can expect.

You should learn syncronization control programming, then use w32 (or Unix)
to create your own dll's. After that step, you may shine on Perl altogether.

-good luck-
.



Relevant Pages

  • Re: What doesnt lend itself to OO?
    ... > system design within that context seriously). ... >>The first line exists in the server. ... > objects between client and server i.e. as far as the client code is ... the message data packet data in the server between requests, ...
    (comp.object)
  • Re: .Net Scalability problem
    ... LoadRunner will peak out a server with a few virtual users. ... To get an idea of load, ... Fire off the test client and watch the number of ... > So I think that the MTC generate concurrent connection and per ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Connection lost at same time every hour (sometimes)
    ... After making the two following alterations on the server the problem seems ... After analyze your ipconfig on SBS and client, ... Then, other connection is good, ...
    (microsoft.public.windows.server.sbs)
  • Re: server disconnection - very often
    ... Reason of permanent popups is VMware server aplication on clients. ... Run CEICW to configure the network of SBS: ... Two network adapters - manual router connection to broadband ... Uninstall VMware on client. ...
    (microsoft.public.windows.server.sbs)
  • Re: Lan setup 2 nic
    ... The external nic only has TCP/IP enabled. ... Ipconfig of the server is looking good, but the client is still missing the ... > connection so we have a 2 nic with router setup now. ...
    (microsoft.public.windows.server.sbs)