public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
byte[] receiveData = new byte[50];
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
System.out.println(getLocalIpAddress());
DatagramSocket serverSocket;
try {
serverSocket = new DatagramSocket(57111);
serverSocket.receive(receivePacket);
String response = new String(receivePacket.getData(), 0,
receivePacket.getLength(), "UTF-8");
TextView t = (TextView) findViewById(R.id.textView1);
t.setText(String.valueOf(new String(response)));
} catch (SocketException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}