Never mind... just found problem/solution. The problem was the extra junk in memory allocated for the packet. The solution: msg = new String(packet.getData()).substring(0, packet.getLength()); .. publishProgress(msg); java.net sucks...
On Oct 18, 4:20 pm, chcat <[email protected]> wrote: > I am trying to update TextView in my Activity with text messages from > DatagramServer ( see below) > The problem I have is that "backgound UDP server receives plenty of > traffic, but onProgessUpdate is ever executed only once so only the > first of the messages appear in the TextView > Any idea what is my error here would be appreciated... > > public class MyActivity extends Activity { > > TextView txtStatus; > // txtStatus initialized > > new BackgroundAsyncTask().execute(); > > public class BackgroundAsyncTask extends > AsyncTask<Void, String, Void> { > public static final String SERVERIP = "127.0.0.1"; // > 'Within' the > emulator! > public static final int SERVERPORT = 2222; > private DatagramSocket socket; > > protected Void doInBackground(Void... params) > { > try { > InetAddress serverAddr = > InetAddress.getByName(SERVERIP); > Log.d("UDP", "S: Waiting for connection..."); > socket = new DatagramSocket(SERVERPORT, > serverAddr); > > while(true) > { > byte[] buf = new byte[1024]; > DatagramPacket packet = new > DatagramPacket(buf, buf.length); > Log.i("telemetry server", " waiting > for packet"); > socket.receive(packet); > > Log.i("received", new > Integer(packet.getLength()).toString()); > Log.i("UDPServer received:", new > String(packet.getData())); > > publishProgress(new > String(packet.getData())); > > } > > } catch (Exception e) { > > Log.i("Dbg server", e.getMessage()); > > } // end of try > Log.i("Dbg server", "Dbg server: Done."); > socket.close(); > > return null; > } > > @Override > protected void onPostExecute(Void result) { > // TODO Auto-generated method stub > //it will never been shown in this exercise... > > } > > @Override > protected void onPreExecute() { > // TODO Auto-generated method stub > > } > > @Override > protected void onProgressUpdate(String... values) { > txtStatus.append(values[0] + "\n"); > > } > } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

