Hi,
I tried a very simple UDP communication as follows: The code simply
sends a UDP packet to the hosting computer (the same machine on which
the emulator runs. )
package com.android.quoteclient;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import java.io.*;
import java.net.*;
public class QuoteClient extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
DatagramSocket socket = null;
try {
socket = new DatagramSocket();
} catch ( SocketException e) {
e.printStackTrace(); // The code fails HERE!!!
}
byte[] buf = new byte[32];
String addr = "171.64.X.X"; // my laptop IP
InetAddress address = null;
try {
address = InetAddress.getByName(addr);
} catch ( UnknownHostException e ) {
e.printStackTrace();
}
DatagramPacket packet = new DatagramPacket(buf, buf.length,
address, 4445);
try {
socket.send(packet);
} catch (IOException e) {
e.printStackTrace();
}
tv.setText("Done");
setContentView(tv);
}
}
I receive an error "Socket Exception." Is DatagramSocket() not
allowed?
Hun
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---