I have a little C++/Java - Socket Server (UDP) running on my PC. Now, i want to connect with my Android App to the Server. But when i send a package my App crash.
public void Socketinit() {
// 1. Socket erstellen!
try {
serverAddr = InetAddress.getByName("192.168.0.101");
socket = new DatagramSocket();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SocketException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
createListeners();
}
and
entprivate void createListeners() {
confirm.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
buf = input.getText().toString().getBytes();
DatagramPacket packet = new DatagramPacket(buf,buf.length, serverAddr, SERVERPORT);
try {
socket.send(packet);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
It crashs on "socket.send(packet);" I can connect to my Server via C++ so the Server is up and running. Where is the Clientproblem in my code ?
thanks