NAME

Net::UCP - Perl extension for EMI - UCP Protocol.

SYNOPSIS

    use Net::UCP;

    $emi = Net::UCP->new(
	         	 SMSC_HOST   => 'smsc.somedomain.tld', 
		         SMSC_PORT   => 3024, 
		         SENDER_TEXT => 'My Self 123', 
		         SRC_HOST=   => 'my.host.tld', 
		         SRC_PORT    => '1666'
			 );

DESCRIPTION

This module implements a Client Interface to the EMI - UCP Interface specification, This Protocol can be used to comunicate with an SMSC (Short Message Service Centre)

Usually the Network connection is based on TCP/IP or X.25.

The EMI/UCP specification can be found online. :)

This Class can be used to send an SMS message to an SMSC. (Text messages and Binary Messages)

You will of course be required to have a valid login at the SMSC to use their services. (Unless there is an SMSC which provides their services for free. Please, let me know about any such service provider. :-)

A Net::UCP object must be created with the new() constructor. Once this has been done, all commands are accessed via method calls on the object.

EXAMPLE

    use Net::UCP;
    
    ($recipient,$text,$sender) = @ARGV;
     
    my ($acknowledge,$error_number,$error_text);

    $emi = Net::UCP->new(SMSC_HOST   => 'smsc.somedomain.tld',
			 SMSC_PORT   => 3024,
			 SENDER_TEXT => 'MyApp',
			 SRC_HOST    => '10.10.10.21', #optional see below
			 SRC_PORT    => '1666',        #optional see below
			 WARN        => 1
			 ) or die("Failed to create SMSC object");
    
    $emi->open_link() or die("Failed to connect to SMSC");

    ($acknowledge,$error_number,$error_text) = $emi->login(
							   SMSC_ID    => 'your_account_id',
							   SMSC_PW    => 'your password',
							   SHORT_CODE => 'your Auth Code',
							   OTON       => '5',        #optional
							   ONPI       => '1',        #optional 
							   VERS       => '0100',     #optional
							   );
    
    die ("Login to SMSC failed. Error nbr: $error_number, Error txt: $error_text\n") unless($acknowledge);
    
    ($acknowledge,$error_number,$error_text) = $emi->send_sms(
							      RECIPIENT      => $recipient, #mand.
							      MESSAGE_TEXT   => $text,      #opt
							      SENDER_TEXT    => $sender,    #opt
							      UDH            => $udh,       #opt
							      FLASH          => $flash,     #opt 
							      MESSAGE_BINARY => $b_mess,    #opt
							      );
    
    die("Sending SMS failed. Error nbr: $error_number, Error txt: $error_text\n") unless($acknowledge);
    
    $emi->close_link();

CONSTRUCTOR

new()

The parameters may be given in arbitrary order.

SMSC_HOST=> Mandatory. The hostname or ip-address of the SMSC.

SMSC_PORT=> Optional. The TCP/IP port number of your SMSC. If omitted, port number 3024 will be used by default.

SMSC_HOST=> Optional. Your ip appdress.

SRC_PORT=> Optional. The TCP/IP source port number. You need to set it if you want to use auth. method based on AC.

SENDER_TEXT=> Optional. The text that will appear in the receivers mobile phone, identifying you as a sender. If omitted, the text 'Net::UCP' will be used by default. You will probably want to provide a more meaningful text than that.

TIMEOUT=> Optional. A timeout, given in seconds, to wait for an acknowledgement of an SMS message transmission. The value must be numeric, positive and within the range of 0 (zero) to 60. Failing this, or if the parameter is omitted, the default timeout of 15 seconds will be applied. The value of this parameter will be used in all calls to the send_sms() method. If the SMSC does not respond with an ACK or a NACK during this period, the send_sms() method will return a NACK to the caller. If the value of 0 (zero) is given, no timeout will occur but the send_sms() method will wait indefinitively for a response. Note that the value given to the constructor can temporarily be overruled in the call to the send_sms() method. As a final note, please remember that not all systems have implemented the alarm() call, which is used to create a timeout. On such systems, this module will still do a blocking call when reading data from the SMSC.

WARN=> Optional. If this parameter is given and if it evaluates to true, then any warnings and errors will be written to STDERR. If omitted, or if the parameter evaluates to false, then nothing is written to STDERR. It is strongly recommended to turn on warnings during the development of an application using the Net::UCP module. When development is finished, the developer may chose to not require warnings but to handle all error situations completely in the main application by checking the return values from Net::UCP.

The constructor returns undef if mandatory information is missing or invalid parameter values are detected. In this case, the object is discarded (out of scope) by the Perl interpreter and you cannot call any methods on the object handle.

Any errors detected will be printed on STDERR if the WARN=> parameter evaluates to true.

Test the return value from the constructor!

METHODS

open_link()

Open the communication link to the SMSC. In reality, this opens up a socket to the SMSC. Be aware that this is not an authenticated login but that the login() method must also be called before any SMS messagescan be sent to the SMSC if you will use an Authentication based on Login and Password.

open_link() is useful since the main application can verify that it's at all possible to communicate with the SMSC. (Think: getting through a firewall.)

This method takes no parameters since it will use the data given in the constructor parameters.

Any errors detected will be printed on STDERR if the WARN=> parameter in the constructor evaluates to true.

open_link() returns true on success and undef in case something went wrong.

login()

You are able to use authentication based on Operation 60 of EMI Protocol. Authenticates against the SMSC with the given SMSC-id and password.

or

Directly through Operation 51. Authenticates against the SMSC with the given SHORT_CODE (AC parameter).

If the open_link() method has not explicitly been called by the main application, the login() method will do it before trying to authenticate with the SMSC.

The parameters may be given in arbitrary order.

SHORT_CODE=> A valid Authentication Code Mandatory for Auth based on OP 51.

SMSC_ID=> A string which should be a valid account ID at the SMSC.

SMSC_PW=> A valid password at the SMSC.

Optional Parameters (Beta):

OTON=> Originator Type of Number

it could be :

1 = International Number (Starts with the country code) 
2 = National Number (Default value is omitted)
6 = Abbreviated Number (short number alias)              

ONPI=> Originator Numbering Plan Id

it could be :

1 = E.164 address (default value if omitted)
3 = X.121 address
5 = Private (TCP/IP address/abbreviated number address)

STYP=> Subtype of Operation

1 = add item to mo-list
2 = rmeove item from mo-list
3 = verify item mo-list
4 = add item to mt-list
5 = remove item from mt-list
6 = verify item mt-list

VERS=> (...My Test...) default value is 0100

Any errors detected will be printed on STDERR if the WARN=> parameter in the constructor evaluates to true.

Return values:

In void context, login() will always return undef. login() will return a true value if you will use it only to set Authentication Code.

In scalar context, login() will return true for success, false for transmission failure and undef for application related errors. Application related errors may be for instance that a mandatory parameter is missing. All such errors will be printed on STDERR if the WARN=> parameter in the constructor evaluates to true.

In array context, login() will return three values: ($acknowledge, $error_number, $error_text); where $acknowledge holds the same value as when the method is called in scalar context (i.e. true, false or undef), $error_number contains a numerical error code from the SMSC and $error_text contains a (relatively) explanatory text about the error.

Be aware that both $error_number and $error_text are provided in a response from the SMSC, which means that the data quality of these entities depends on how well the SMSC has implemented the protocol.

If $acknowledge is undef, then $error_number will be set to 0 (zero) and $error_text will contain a zero length string.

It is strongly recommended to call login() in an array context, since this provides for an improved error handling in the main application.

send_sms()
EXAMPLE
    $binary_message  = "024A3A7125CD7DD1A1A5CD7DB1BDD994040045225D04985585D85D84106906985D84984A85585D85D84104D";
    $binary_message .= "04104D85D0690410A24824C49A6289B09D093126986A800";

    $emi->send_sms(
		   RECIPIENT      =>'391232345678', 
		   MESSAGE_TEXT   => 'A Message', 
		   SENDER_TEXT    => 'Marco', 
		   FLASH          => 1,
		   UDH            => '050415811581',
		   MESSAGE_BYNARY => $binary_message,
		   TIMEOUT        => 5 
		   );

Submits the SMS message to the SMSC (Operation 51) and waits for an SMSC acknowledge.

The parameters may be given in arbitrary order.

RECIPIENT=> Mandatory.

This is the phone number of the recipient in international format with leading a '+' or '00'.

MESSAGE_TEXT=> Optional. A text message to be transmitted.

It is accepted to transfer an empty message, so if this parameter is missing, a space character will be sent (0x20).

FLASH=> Optional. With this parameter you are able to send a Class 0 messages.

1) Set to 1 Flash Message enabled     (Class 0)
2) Other value Flash Message disabled (No Class)

MESSAGE_BINARY=> Optional. A binary message to be transmitted.

UDH=> Optional. User Data Header (you need to set UDH to use MESSAGE_BINARY).

First UDH Octet (length) will be internally calculated for this reason you need to omitted it.

SENDER_TEXT=> Optional. The text that will appear in the receivers mobile phone, identifying you as a sender.

In this version you are able to set:

          1) alphanumeric sender  ( Marco81        )
          2) numeric sender       ( 67166155111    )
          3) international format ( +3934112331112 ) 

This text will temporarily replace the text given to the constructor. If omitted, the text already given to the constructor will be used.

TIMEOUT=> Optional.

A timeout, given in seconds, to wait for an acknowledgement of this SMS message transmission. The value must be numeric, positive and within the range of 0 (zero) to 60. Failing this, or if the parameter is omitted, the timeout established in the new() constructor will be applied. If the SMSC does not respond with an ACK or a NACK during this period, the send_sms() method will return a NACK to the caller. If the value of 0 (zero) is given, no timeout will occur but the send_sms() method will wait indefinitively for a response. On a system that has not implemented the alarm() call, which is used to create a timeout, this module will still do a blocking call when reading data from the SMSC.

Any errors detected will be printed on STDERR if the WARN=> parameter in the constructor evaluates to true.

Return values:

In void context, send_sms() will always return undef.

In scalar context, send_sms() will return true for success, false for transmission failure and undef for application related errors. Application related errors may be for instance that a mandatory parameter is missing. All such errors will be printed on STDERR if the WARN=> parameter in the constructor evaluates to true.

In array context, send_sms() will return the three values: ($acknowledge, $error_number, $error_text); where $acknowledge holds the same value as when the method is called in scalar context (i.e. true, false or undef), $error_number contains a numerical error code from the SMSC and $error_text contains a (relatively) explanatory text about the error.

Be aware that both $error_number and $error_text are provided in a response from the SMSC, which means that the data quality of these entities depends on how well the SMSC has implemented the protocol.

If $acknowledge is undef, then $error_number will be set to 0 (zero) and $error_text will contain a zero length string.

It is strongly recommended to call send_sms() in array context, since this provides for an improved error handling in the main application.

Note! The fact that the message was successfully transmitted to the SMSC does not guarantee immediate delivery to the recipient or in fact any delivery at all.

About the timeout. Not all Perl systems are able to provide the timeout. The timeout is internally implemented with the alarm() call. If your system has implemented alarm(), then any timeout value provided will be honored. If not, you may provide any value you wish for the timeout, it will still be ignored and reading the ACK from the SMSC will block until everything is read.

If the SMSC fails to send you the full response your application will freeze. If your system does implement alarm() but you do not provide any timeout value, then the default timeout of 15 seconds will be applied.

You may test this on your own system by executing the following on a command line:

perl -e "alarm(0)"

If the response is that alarm() is not implemented, then you're out of luck. You can still use the module, but in case the SMSC doesn't respond as expected your application will wait indefinitively.

logout()
close_link()

logout() is an alias for close_link(). Whichever method name is used, the very same code will be executed.

What goes up, must also come down. If the main application will continue working on other tasks once the SMS message was sent, it is possible to explicitly close the communications link to the SMSC with this method.

If the Net::UCP object handle (returned by the new() method) goes out of scope in the main application, the link will be implicitly closed and in this case it is not necessary to explicitly close the link.

In reality, this method closes the socket established with the SMSC and does some additional house-keeping. Once the link is closed, a new call to either open_link() or to login() will try to re-establish the communications link (socket) with the SMSC.

returns nothing (void)

read_mo()

it needs two parameters :

first parameter is timeout in second. It could be 0 or < 0 if you don't want to set timeout. second parameter is mandatory and it's the path where read_mo() method will store dump of MO messages.

With read_mo() method you are able to get back MO messages and store it in a text file.

EXAMPLE
    $emi->read_mo(
		  '50',
		  '/path/dump.txt',
		  );

without timeout

  $emi->read_mo(
                '0',
                '/NEW/path/dump.txt',
                );

SEE ALSO

IO::Socket,

AUTHOR

Marco Romano, <nemux@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2004 by Marco Romano

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available.