public class MainActivity extends ActionBarActivity {
LinearLayout vpad;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
vpad.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
String vtmp="Testing";
send_udp(vtmp);
return true;
}
});
public void send_udp(String msg){
DatagramSocket cs=null;
InetAddress ipx=null;
byte[] ip_byte=new byte[]{(byte)192,(byte)168,(byte)4,(byte)1};
try {
ipx = InetAddress.getByAddress(ip_byte);
} catch (Exception E){
}
byte[] xdata=msg.getBytes();
DatagramPacket sp=new DatagramPacket(xdata,xdata.length,ipx,87);
try{
cs=new DatagramSocket();
cs.send(sp);
} catch (Exception E) {
} finally {
if(cs!=null){
cs.close();
}
}
}
i have ESP8266 set as UDP server.. i've tried with Delphi 7 as UDP client, it work.. but with this android code, it didnt receive anything.. please help me..