Before you have to put this code to the class that extends service/wallpaperservice
new Thread() {
@Override
public void run() {
try {
LocalServerSocket server = new LocalServerSocket(“myArdress”);
Log.d(“SERVER READY”, “Server is ready.”);
while(continueSocket) {
LocalSocket receiver = server.accept();
if (receiver != null) {
InputStream input = receiver.getInputStream();
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[16384];
while ((nRead = input.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
}
buffer.flush();
byte[] datainput = buffer.toByteArray();
String stringa = new String(datainput) ;
Log.d(“GOT DATA”, stringa);
if (stringa.equals(“what do you want”)) {
//Do what do tou want
}
}
}
server.close();
} catch (IOException ex) {
Log.wtf(“IOEXCEPTION”, ex);
}
}
}.start();
After in the Activity you can call the server with this simple code :
try {
LocalSocket sender = new LocalSocket();
sender.connect(new LocalSocketAddress(“myArdress”));
String data = “wath do you want send”;
Log.d(“SENT DATA”, data);
sender.getOutputStream().write(data.getBytes());
sender.getOutputStream().close();
sender.close();
} catch (IOException ex) {
Log.wtf(“IOEXCEPTION”, ex);
}
I’m not sure exactly why but this weblog is loading very slow for me.
Is anyone else having this problem or is it a issue on my end?
I’ll check back later and see if the problem still exists.