NAME
Net::HL7::Daemon
SYNOPSIS
my $d = new Net::HL7::Daemon( LocalPort => 12002, Listen => 5 );
DESCRIPTION
The Net::HL7::Daemon class provides a Daemon, roughly based on the well known HTTP::Daemon class. The daemon wraps IO::Socket::INET so that incoming connections are returned as Net::HL7::Daemon::Client objects. Other than that the Daemon class doesn't do all that much. However, this allows you to use the Daemon class as a base for more elaborate servers, like preforking or multi-threaded servers. See the Perl Cookbook for examples on this, and think Net::HL7::Daemon where you see IO::Socket.
METHODS
- $d = new Net::HL7::Daemon()
-
Create a new instance of the Daemon class. Arguments are the same as for the IO::Socket::INET. Default settings are: Listen = SOMAXCONN, Proto = tcp, Reuse = 1.
- accept([$pkg])
-
This method is the same as IO::Socket::accept but returns an Net::HL7::Daemon::Client reference. It returns undef if you specify a timeout and no connection is made within that time. In a scalar context the returned value will be a reference to a object of the Net::HL7::Daemon::Client class which is another IO::Socket::INET subclass. In a list context a two-element array is returned containing the new Net::HL7::Daemon::Client reference and the peer address; the list will be empty upon failure.
- getHost()
-
Returns the host where this daemon can be reached.
- getPort()
-
Returns the port on which this daemon is listening.
NAME
Net::HL7::Daemon::Client
DESCRIPTION
The Net::HL7::Daemon::Client is also a IO::Socket::INET subclass. Instances of this class are returned by the accept() method of Net::HL7::Daemon.
METHODS
- $d = new Net::HL7::Daemon::Client()
-
Create a new instance of the Client class. Arguments are the same as for the IO::Socket::INET. Normally, you shouldn't do this...
- getRequest()
-
Get the current request on this client. The current request is either the request that has been read by the getNextRequest() method, or if that hasn't been called yet, the request read from the socket. The latter is implemented by calling getNextRequest. If both fail,
undef
is returned. In case of failure, then the Net::HL7::Daemon::Client object ($c) should be discarded, and you should not call this method again.Potentially, a HL7 client can receive more than one message. So discard the client only when there's no more requests pending, or the delivering service might experience timeouts.
- getNextRequest()
-
Read data from the socket and turn it into an Net::HL7::Request object which is then returned. It returns
undef
if reading of the request fails. If it fails, then the Net::HL7::Daemon::Client object ($c) should be discarded, and you should not call this method again. Potentially, a HL7 client can receive more than one message. So discard the client only when there's no more requests pending, or the delivering service might experience timeouts. - sendAck($res)
-
Write a Net::HL7::Messages::ACK message to the client as a response, to signal success. You may provide your own Net::HL7::Response, but it is better to rely on the ACK that is generated internally.
- sendNack($errMsg, $res)
-
Write a Net::HL7::Messages::ACK message to the client as a response, with the Acknowledge Code (MSA(1)) set to CE or AE, depending on the original request, to signal an error.
- sendResponse($res)
-
Write a Net::HL7::Reponse object to the client as a response. This can hold an arbitrary HL7 message.
SEE ALSO
RFC 2068
COPYRIGHT
Copyright 2003, D.A.Dokter
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.