Я пытаюсь отправить строку из raspberry pi на устройство Android. Ниже приведен мой код на стороне Android
package com.example.videostreamer;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.widget.ImageView;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private Socket s;
private boolean mconnectexception = false;
private static final String TAG = "MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
frame2video f2v = new frame2video();
f2v.execute();
}
public class frame2video extends AsyncTask<Void, Void, Void> {
protected void onPreExecute() {
}
protected Void doInBackground(Void... params) {
BufferedReader dis;
String message;
try {
s = new Socket("192.168.0.132", 5001);
Log.d(TAG, "Connection Successful..!");
} catch (IOException e) {
e.printStackTrace();
mconnectexception = true;
}
if (mconnectexception) {
Log.d(TAG, "Connection not Available");
}
while (true) {
try {
if (s!=null) {
dis = new BufferedReader(new InputStreamReader(s.getInputStream(),"utf8"));
message = dis.readLine();
Log.d(TAG, "Here is it"+message);
}
} catch (IOException e) {
e.printStackTrace();
Log.d(TAG,"Something is wrong");
}
return null;
}
}
}
}
На стороне Raspberry pi код Python выглядит следующим образом:
import socket
import time
import base64
from socket import gethostbyname, gethostname
listensocket=socket.socket()
Port=5001
maxConnections=999
IP=socket.gethostname()
print(IP)
listensocket.bind(('',Port))
listensocket.listen(maxConnections)
print('Server started at '+IP+' on Port'+str(Port))
(clientsocket,address)=listensocket.accept()
print("New Connection Made: "+str(address))
#listensocket.close()
running=True
times=1
while running:
time.sleep(3)
msg="The time is\n"
print(msg)
listensocket.send(bytes(msg,"utf-8"))
times+=1
if (times==30):
running=False
#listensocket.close()
#listensocket.close()
На стороне Android журнал выглядит следующим образом (не показывает никакихошибка)
2019-10-08 23:22:32.884 7650-7650/? I/e.videostreame: Not late-enabling -Xcheck:jni (already on)
2019-10-08 23:22:32.934 7650-7650/? W/e.videostreame: Unexpected CPU variant for X86 using defaults: x86
2019-10-08 23:22:33.501 7650-7650/com.example.videostreamer W/e.videostreame: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
2019-10-08 23:22:33.501 7650-7650/com.example.videostreamer W/e.videostreame: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
2019-10-08 23:22:33.555 7650-7677/com.example.videostreamer D/MainActivity: Connection Successful..!
2019-10-08 23:22:33.559 7650-7650/com.example.videostreamer D/OpenGLRenderer: Skia GL Pipeline
2019-10-08 23:22:33.612 7650-7679/com.example.videostreamer I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
2019-10-08 23:22:33.613 7650-7679/com.example.videostreamer I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
2019-10-08 23:22:33.613 7650-7679/com.example.videostreamer I/OpenGLRenderer: Initialized EGL, version 1.4
2019-10-08 23:22:33.613 7650-7679/com.example.videostreamer D/OpenGLRenderer: Swap behavior 1
2019-10-08 23:22:33.613 7650-7679/com.example.videostreamer W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2019-10-08 23:22:33.613 7650-7679/com.example.videostreamer D/OpenGLRenderer: Swap behavior 0
2019-10-08 23:22:33.615 7650-7679/com.example.videostreamer D/EGL_emulation: eglCreateContext: 0xe4f85180: maj 3 min 0 rcv 3
2019-10-08 23:22:33.616 7650-7679/com.example.videostreamer D/EGL_emulation: eglMakeCurrent: 0xe4f85180: ver 3 0 (tinfo 0xe4f83680)
2019-10-08 23:22:33.706 7650-7679/com.example.videostreamer D/EGL_emulation: eglMakeCurrent: 0xe4f85180: ver 3 0 (tinfo 0xe4f83680)
на стороне Python, соединение успешно установлено, но в строке:
listensocket.send(bytes(msg,"utf-8")
Я получаю ошибку BrokenPipeError: [Err 32] Broken pipe. Больше ничего не появляется в журнале Java.
Я новичок в Java и, возможно, делаю некоторые глупые ошибки .. :( Любая помощь будет отличной ..!