Package javax.microedition.io

Examples of javax.microedition.io.Datagram


    protected void listenForMessages() throws Exception {
        _connection = openPort();
        DatagramConnection dCon = (DatagramConnection) _connection;
        while( true ) {
            Datagram dgram = dCon.newDatagram( dCon.getMaximumLength() );
            dCon.receive( dgram );
            if( isRunning() && listenerRegistry.listenerIsSet() ) {
                new DatagramProcessor( dgram ).start();
            } else {
                yield();
View Full Code Here


                   
                    StaticDataHelper.log("[SMS] Returning from run() while 'stop' is " + stop);
                    return;
                }
               
                Datagram d = dc.newDatagram(dc.getMaximumLength());
               
                //
                dc.receive(d);
                //
               
                String address = new String(d.getAddress());
                StaticDataHelper.log("[SMS] Message received: ");
                StaticDataHelper.log("[SMS] From: " + address);
               
                /*
                 * The NotificationProcessor reads the
                 * binary SMS notification message and extracts
                 * informations from it that are stored into a
                 * passed hashtable
                 */
                NotificationProcessor processor = new NotificationProcessor();
               
                /*
                 * The hashtable to be passed to the
                 * notification processor to be filled
                 * with data from the binary SMS from
                 * the server. See
                 * NotificationProcessor.processMessage
                 */
                Hashtable smsData = new Hashtable();
               
                //getData() returns an array of bytes
                processor.processMessage(smsData, removeHeader(d.getData()));
               
                if (smsData != null) {
                   
                    StaticDataHelper.log("[SMS] Data from SMS message:\n" + smsData.toString());
           
View Full Code Here

            // Convert the message to a byte array for sending.
            final byte[] bufOut = _msg.getBytes();

            // Create a datagram and send it across the connection.
            final Datagram outDatagram =
                    _conn.newDatagram(bufOut, bufOut.length);
            _conn.send(outDatagram);

            // Expect a response
            final byte[] bufIn = new byte[8];
            final Datagram inDatagram = _conn.newDatagram(bufIn, bufIn.length);
            _conn.receive(inDatagram);
            final String response = new String(inDatagram.getData());

            if (response.startsWith("RECEIVED")) {
                // Display the status message on the event thread.
                _app.invokeLater(new Runnable() {
                    public void run() {
View Full Code Here

                                .getConnection();
                try {
                    final byte[] buf = new byte[256];

                    // Send request
                    Datagram packet = udpCon.newDatagram(buf, buf.length);
                    udpCon.send(packet);

                    // Get response
                    packet = udpCon.newDatagram(buf, buf.length);
                    udpCon.receive(packet);

                    // Display response
                    final String message =
                            new String(packet.getData(), 0, packet.getLength());
                    displayMessage(_connectionName + " " + message);
                } catch (final IOException ioe) {
                    displayMessage(ioe.toString());
                } finally {
                    if (udpCon != null) {
View Full Code Here

    public void run() {
      do {
        try {
          //1. pickup the message and corresponding request
          byte[] message = (byte[]) m_SendQueue.take();
          Datagram req = (Datagram)
              m_Requests.remove(new Integer(ModbusUtil.registersToInt(message)));
          //2. create new Package with corresponding address and port
          /*FPFDatagram res = new Datagram(message,
              message.length,
              req.getAddress(),
              FPFreq.getPort());*/
          Datagram res = m_Socket.newDatagram(message,message.length , req.getAddress());
          m_Socket.send(res);
          if (Modbus.debug) System.out.println("Sent package from queue.");
        } catch (Exception ex) {
          DEBUG:ex.printStackTrace();
        }
View Full Code Here

      do {
        try {
          //1. Prepare buffer and receive package
          byte[] buffer = new byte[256];//max size
          /*FPFDatagram packet = new DatagramPacket(buffer, buffer.length);*/
          Datagram packet = m_Socket.newDatagram(buffer,buffer.length );
          m_Socket.receive(packet);
          //2. Extract TID and remember request
          Integer tid = new Integer(ModbusUtil.registersToInt(buffer));
          m_Requests.put(tid, packet);
          //3. place the data buffer in the queue
View Full Code Here

        msg,
        msg.length,
        m_RemoteAddress,
        m_RemotePort
    );*/
    Datagram req = m_Socket.newDatagram(msg, msg.length,m_RemoteAddress);
    synchronized (m_Socket) {
      m_Socket.send(req);
    }
  }//sendPackage
View Full Code Here

      throws Exception {

    //1. Prepare buffer and receive package
    byte[] buffer = new byte[256];//max size
    //FPFDatagramPacket packet = new DatagramPacket(buffer, buffer.length);
    Datagram packet = m_Socket.newDatagram(buffer, buffer.length);
    synchronized (m_Socket) {
      //FPFm_Socket.setSoTimeout(m_Timeout);
      m_Socket.receive(packet);
    }
    return buffer;
View Full Code Here

    return buffer;
  }//receiveMessage

  public void receiveMessage(byte[] buffer)
      throws Exception {
    Datagram packet = m_Socket.newDatagram(buffer, buffer.length);
    //FPFm_Socket.setSoTimeout(m_Timeout);
    m_Socket.receive(packet);
  }//receiveMessage
View Full Code Here

TOP

Related Classes of javax.microedition.io.Datagram

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.