Here's the scenario:
I'm using OkHttp to send get requests asynchronously which works great. Code as follows:
private void doGetRequest(String url){
Request request = new Request.Builder()
.url(url)
.build();
client.newCall(request)
.enqueue(new Callback() {
@Override
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
Log.i(TAG,"Response: " + response);
}
@Override
public void onFailure(@NotNull Call call, @NotNull final IOException e) {
// Error
Log.e(TAG,"Error: " + e);
requireActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(requireActivity(), getResources().getString(R.string.error, e.toString()), Toast.LENGTH_SHORT).show();
}
});
}
});
}
I'm also using a AsyncTask to decode a Mjpeg stream. Inside the doInBackground function of my AsyncTask I have:
protected Long doInBackground(String... urls) {
//Get InputStream
URL url = new URL(urls[0]);
HttpURLConnection connect = (HttpURLConnection) url.openConnection();
DataInputStream inputStream = new DataInputStream (connect .getInputStream());
mjpegStream = new MjpegInputStreamDefault(inputStream);
//Start decoding mjpeg stream
while (doRun) {
publishProgress(mjpegStream.readMjpegFrame());
}
}
The important takeaway is I'm continuously decoding a network stream over WIFI from the same device that I have to send the GET requests to.
The problem I'm having is as soon as I start the mjpeg stream my GET requests stop being received. If I stop the mjpeg stream eventually my GET requests get received assuming the timeout hasn't been reached yet.
My question is can I be sending and receiving stuff to the same device at the same time? If so why are my requests not getting received while my mjpeg stream is being received?