• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Sockets

vandium

Lurker
Hi,
I'm trying to make a simple app to control various things in my workshop right now I have written a program in java that runs on a raspberry pi which hosts a server. I want my app to be able to connect to the server and send a command to tell the raspberry pi I want the lights on or whatever. I'm having a problem with my app opening a connection to the server every time it tries to send a command the app crashes. I have added the following permission to my AndroidManifest.xml


[HIGH]<uses-permission android:name="android.permission.INTERNET" />[/HIGH]

here is the method I pass my command to to send to my raspberry pi
[HIGH]public class Com{

public void sendCommand(String command){
//System.out.println("Command sent:" + command);

try {
Socket thePi = new Socket("192.168.1.9",3324);
OutputStreamWriter osw = new OutputStreamWriter(thePi.getOutputStream());
PrintWriter toThePi = new PrintWriter(osw);
toThePi.println(command);
toThePi.close();
thePi.close();
}

catch (IOException E){
E.printStackTrace();

}


}

}[/HIGH]


maybe this is the completely wrong way of trying to send commands over the internet? whats causing my app to crash when I try to open a socket?
Thank you,
 
Back
Top Bottom