Groups > Palm OS > Communication Developer Forum > re: socket notification




re: socket notification

re: socket notification
Mon, 20 Aug 2007 16:22:03 -000
I hope this would help even just a bit.  I have this piece of code in a class
that is threaded:

try {
    		/*mc = (MessageConnection)
Connector.open("sms://:5557",Connector.READ,false);*/
    		dc = (DatagramConnection)
Connector.open("datagram://:5557",Connector.READ,false);
    	} catch (Exception ex) {
            /*Alert a = new Alert("CommandsListener", "Cannot
open connection",
                    null, AlertType.ERROR);
            a.setTimeout(5000);
            display.setCurrent(a);*/
    		try {
				sleep(1000);
			} catch (Exception e) {
				e.printStackTrace();
			}
    	}
I actually have the above connection in a while loop to force a connection since
UDP does not have any error sort of checking.  I did it this way because this
class is a listener that listens to an inbound stream from a server.  That's why
it's a separate thread.  
Here's where I handle any incoming data from the socket:
Note that the variable "dc" is the DataConnection instance name.

Datagram dg = dc.newDatagram(100);
        		dc.receive(dg);
        		rcvString = new String(dg.getData(), 0, dg.getLength());

Hope this helps a bit.
Post Reply
about | contact