View Single Post
Old 02-19-2010, 05:06 PM   #2 (permalink)
psantimauro
New Member
 
Join Date: Feb 2010
Model: none
PIN: N/A
Carrier: verizon
Posts: 2
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I dont know if this will help, but here are the source files...


Server Thread
PHP Code:


import java
.io.IOException;

import javax.microedition.io.*;
import javax.wireless.messaging.*;


public class 
RunnerThread implements Runnable
{
    
MessageConnection in;
    
TextMessage msg;
    
bytexxx91;xxx93; payload;
    
//HttpConnection c;
    
DatagramConnection incomingConnection;
    
    
//DatagramConnection incomingconnection = (DatagramConnection)Connector.open("sms://:1234");
    
    
    
public RunnerThread() 
    {
        
System.out.println("Runner Constructing...");
        
System.out.print("Opening conection.");
        
        try{
            
incomingConnection = (DatagramConnection)Connector.open("sms://:1234");        
        }
        catch(
IOException e)
        {
            
System.out.println("\tfailed");
            
System.out.println(e.toString());
        }
        
System.out.println("\tdone");
    }
    public 
RunnerThread(MessageConnection dc)
    {

        
in=dc;
    }

    public 
void run()
    {
        while(
true)
        {
            try
            {

                
System.out.println("top  ==================");
            
                
Datagram sms incomingConnection.newDatagram(incomingConnection.getMaximumLength());
                
incomingConnection.receive(sms);
                
                
bytexxx91;xxx93; payload sms.getData();
                
                
System.out.println(payload);
                
                
//msg = (TextMessage)in.receive();
                //System.out.println(msg.getPayloadText());
                
System.out.println("bottom==================");
                
                
//wait(100);
            
} catch (Exception e)
            {
                
// TODO Auto-generated catch block
                
e.printStackTrace();
                
                
System.out.println(e.toString());
            }
        }
        
        
    }



and the sender thread
PHP Code:
import java.io.IOException;

import javax.microedition.io.Connector;
import javax.microedition.io.Datagram;
import javax.microedition.io.DatagramConnection;
import javax.wireless.messaging.BinaryMessage;
import javax.wireless.messaging.MessageConnection;

import net.rim.device.api.io.DatagramBase;
import net.rim.device.api.io.SmsAddress;
import net.rim.device.api.system.SMSPacketHeader;
import net.rim.device.api.system.SMSParameters;


public class 
MyThread implements Runnable {
    
    
    
DatagramConnection connection null;
    
String sendPrefix "sms://1234567890:1234";
    
Datagram d;
    
    public 
void run() {
        
        
        

        
System.out.print("ADFASFDASFDASFDASFDASDSFASDAFASFDASFDASFD");
        
SmsAddress destinationAddr = new SmsAddress("//1234567890:1234");
        
SMSPacketHeader h destinationAddr.getHeader();
        
h.setStatusReportRequest(false);
        
h.setUserDataHeaderPresent(true);
        
h.setValidityPeriod(SMSParameters.PERIOD_INDEFINITE);
        
h.setDeliveryPeriod(SMSParameters.PERIOD_INDEFINITE);
        
h.setMessageClass(SMSParameters.MESSAGE_CLASS_1);
        
h.setMessageCoding(SMSParameters.MESSAGE_CODING_8_BIT);
        
        
        
        


        
        try 
        {
            
            
int maxDatagramLength connection.getMaximumLength();
            
// note - I have seen this method returning some strange
            // values. If it returns anything bigger than 140 you have
            // to limit your message size to 140 bytes
            
final bytexxx91;xxx93; myUDH = new bytexxx91;xxx93; {
                    
0x06,
                    
0x05,   // application addressing scheme
                    
0x04,   // address size in bytes: 2 x 2 bytes
                    
0x04,   // destination port=1234, little-endian
                    
0x04,   // source port=1234, little-endian
            
};
            
// calculating the remaining space for the data
            
maxDatagramLength -= myUDH.length;
            
bytexxx91;xxx93; message "Bonjour de Montréal".getBytes("UTF-8");
            
// building the actual SMS payload
            
bytexxx91;xxx93; completePayload = new bytexxx91;myUDH.length message.lengthxxx93;;
            
System.arraycopy(myUDH0completePayload0myUDH.length);
            
System.arraycopy(message0completePayloadmyUDH.lengthmessage.length);
            
            
connection = (DatagramConnection)Connector.open("sms://1234567890:1234");
            
connection.newDatagram(message.length);
            ((
DatagramBase)d).setAddressBase(destinationAddr);
            
d.setData(completePayload0completePayload.length);
            
connection.send(d);
            
        
        } catch (
Exception e) {
            
// TODO Auto-generated catch block
            
e.printStackTrace();
        }
        

        
        
        
    }



thanks again
pete
Offline   Reply With Quote