Im trying to make a single UDP app in android studio. Whenever I run the app and press the button the app crashes.
Im using Datagram object to make it. My code seems to be alright but I don´t know where the mistake is. ITS DRIVING ME CRAZY please, help me.
This is the main activity page :
package lumma.e_motionvrplayer;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
public class MainActivity extends AppCompatActivity {
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https/g.co/AppIndexing/AndroidStudio for more information.
*/
private GoogleApiClient client;
//Cierre de la clase
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https/g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
public void clickplay(View v) throws IOException {
try
{
DatagramSocket socket = new DatagramSocket();
byte[] buf = new byte[256];
String messg = "play";
buf = messg.getBytes ();
InetAddress address = InetAddress.getByName ("255.255.255.255");
DatagramPacket packet = new DatagramPacket(buf, buf.length, address, 5000);
socket.send(packet);
}
catch (IOException e)
{
}
}
public void clickrestart(View v) throws IOException {
}
public void clickpause(View v) throws IOException {
}
public void clicknext(View v) throws IOException {
}
public void clickprev(View v) throws IOException {
}
}
Im using Datagram object to make it. My code seems to be alright but I don´t know where the mistake is. ITS DRIVING ME CRAZY please, help me.
This is the main activity page :
package lumma.e_motionvrplayer;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
public class MainActivity extends AppCompatActivity {
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https/g.co/AppIndexing/AndroidStudio for more information.
*/
private GoogleApiClient client;
//Cierre de la clase
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https/g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
public void clickplay(View v) throws IOException {
try
{
DatagramSocket socket = new DatagramSocket();
byte[] buf = new byte[256];
String messg = "play";
buf = messg.getBytes ();
InetAddress address = InetAddress.getByName ("255.255.255.255");
DatagramPacket packet = new DatagramPacket(buf, buf.length, address, 5000);
socket.send(packet);
}
catch (IOException e)
{
}
}
public void clickrestart(View v) throws IOException {
}
public void clickpause(View v) throws IOException {
}
public void clicknext(View v) throws IOException {
}
public void clickprev(View v) throws IOException {
}
}