Udp trouble in Android studio

Julian_13

Commendable
May 20, 2016
1
0
1,510
0
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 {
}
}
 
Thread starter Similar threads Forum Replies Date
T Apps General Discussion 1
john vitz Apps General Discussion 5
T Apps General Discussion 1
Speculation Apps General Discussion 5
C Apps General Discussion 1
F Apps General Discussion 3
B Apps General Discussion 4
D Apps General Discussion 1
A Apps General Discussion 2
I Apps General Discussion 1
A Apps General Discussion 2
M Apps General Discussion 3
U Apps General Discussion 2
N Apps General Discussion 6
N Apps General Discussion 5
Jonathan Conrad Apps General Discussion 3
187Flatliner Apps General Discussion 7
F Apps General Discussion 7
C Apps General Discussion 1
D Apps General Discussion 5

ASK THE COMMUNITY

TRENDING THREADS