Example #1
0
/**
 * See pcsl_datagram.h for definition.
 */
int pcsl_datagram_write_start(
    void *handle,
    unsigned char *pAddress,
    int port,
    char *buffer,
    int length,
    int *pBytesWritten,
    void **pContext)
{
    int res;
    res = (int)javacall_datagram_sendto_start((javacall_handle) handle,pAddress,
        port,buffer,length,pBytesWritten,pContext);
        
    return javacall_to_pcsl_result(res);
}
Example #2
0
/**
 * send an SMS message
 *
 * Actually 
 *   - sends a datagramm to 11101 port, it can be received by JSR205Tool.jar (used in TCK tests)
 *   - writes a message to the console (it is enough for native tests)
 * The address to send datagram is one of the following:
 *   - 127.0.0.1 if JSR_205_DATAGRAM_HOST environment variable is not send
 *   - JSR_205_DATAGRAM_HOST environment variable value (if set).
 *
 * Refer to javacall_sms.h header for complete description.
 */
int javacall_sms_send(  javacall_sms_encoding    msgType, 
                        const unsigned char*    destAddress, 
                        const unsigned char*    msgBuffer, 
                        int                     msgBufferLen, 
                        unsigned short          sourcePort, 
                        unsigned short          destPort) {

    javacall_handle datagramHandle;
    javacall_result ok;
    int pBytesWritten = 0;
    void *pContext;
    unsigned char *pAddress;

    javacall_int64 timeStamp = 0;
    const char* recipientPhone = destAddress;
    char* senderPhone = "+1234567";
    int encodedSMSLength;
    char* encodedSMS;

    char* IP_text = getProp("JSR_205_DATAGRAM_HOST", "127.0.0.1");
    //JSR205Tool listens on 11101 port, but sends to 11100 port
    int smsRemotePortNumber = getIntProp("JSR_205_SMS_OUT_PORT", 11101);

    javacall_network_init_start();
    pAddress = getIPBytes_nonblock(IP_text);

    encodedSMS = encodeSmsBuffer(msgType, destPort, timeStamp, recipientPhone, senderPhone, 
        msgBufferLen, msgBuffer, &encodedSMSLength);

    ok = javacall_datagram_open(0, &datagramHandle);
    if (ok == JAVACALL_OK) {
        ok = javacall_datagram_sendto_start(datagramHandle, pAddress, smsRemotePortNumber,
            encodedSMS, encodedSMSLength, &pBytesWritten, &pContext);
        if (ok != JAVACALL_OK) {
            javacall_print("Error: SMS sending - datagram blocked.\n");
        }
    }

    javacall_print("## javacall: SMS sending...\n");

    javanotify_sms_send_completed(JAVACALL_SMS_SENDING_RESULT_SUCCESS, 13);

    return 1;
}