|
|
@@ -0,0 +1,33 @@ |
|
|
|
package com.example.lfrmobileapp; |
|
|
|
|
|
|
|
import android.os.AsyncTask; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.io.OutputStream; |
|
|
|
import java.net.Socket; |
|
|
|
|
|
|
|
private class DataTransferAsyncTask extends AsyncTask<Void, Void, Void> { |
|
|
|
private static final int sendRatePerSecond = 2; |
|
|
|
private String hostname; |
|
|
|
private int portNumber; |
|
|
|
DataTransferAsyncTask(String hostname, int portNumber) { |
|
|
|
this.hostname = hostname; |
|
|
|
this.portNumber = portNumber; |
|
|
|
} |
|
|
|
@Override |
|
|
|
protected Void doInBackground(Void... params) { |
|
|
|
try { |
|
|
|
Socket socket = new Socket(hostname, portNumber); |
|
|
|
OutputStream outputStream = socket.getOutputStream(); |
|
|
|
while (!isCancelled()) { |
|
|
|
outputStream.write("data".getBytes()); |
|
|
|
outputStream.flush(); |
|
|
|
Thread.sleep(1000 / sendRatePerSecond); |
|
|
|
} |
|
|
|
socket.close(); |
|
|
|
} catch (IOException | InterruptedException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |