我的服务器正在向我的Android客户端发送一些JSON字符串,但发生了一些错误。请帮助:
我的服务器正在尝试将以下文本发送到我的Android客户端 服务器输出:(2D字符串数组)
[
[
"testingg",
"3",
"24:df:6a:e7:47:3c",
"f8:e7:1e:1e:21:58",
"f8:e7:1e:1d:fd:3c"
],
[
"moreee",
"4",
"24:c9:a1:36:03:48",
"24:c9:a1:35:fe:38",
"24:c9:a1:36:05:08",
"24:c9:a1:36:04:38"
],
[
"lailailai",
"4",
"24:c9:a1:36:03:48",
"24:c9:a1:36:05:08",
"24:c9:a1:35:fe:38",
"24:c9:a1:36:03:48"
],
[
"tryyyy",
"2",
"24:c9:a1:36:03:48",
"24:c9:a1:35:fe:38"
],
[
"testyyy",
"2",
"24:c9:a1:36:03:48",
"24:c9:a1:36:05:08"
],
[
"hahaha",
"3",
"24:c9:a1:36:03:48",
"24:c9:a1:35:fe:38",
"24:c9:a1:36:05:08"
],
[
"ehyyy",
"2",
"24:c9:a1:36:03:48",
"24:c9:a1:36:05:08"
],
[
"offlinet",
"2",
"24:c9:a1:36:03:48",
"e8:de:27:5b:a2:ea"
],
[
"opop",
"4",
"24:c9:a1:36:03:48",
"24:c9:a1:36:02:98",
"24:c9:a1:36:03:48",
"24:c9:a1:36:02:98"
],
[
"tt",
"5",
"24:c9:a1:36:03:48",
"24:c9:a1:36:05:08",
"24:c9:a1:35:fe:38",
"24:c9:a1:36:03:48",
"24:c9:a1:36:05:08"
],
[
"Input",
"6",
"24:c9:a1:36:03:48",
"24:c9:a1:35:fe:38",
"70:8b:cd:b3:17:2c",
"24:c9:a1:36:03:48",
"70:8b:cd:b3:17:2c",
"24:c9:a1:36:03:48"
],
[
"cekkk",
"5",
"24:c9:a1:36:03:48",
"24:c9:a1:36:05:08",
"24:c9:a1:35:fe:38",
"24:c9:a1:36:05:78",
"24:c9:a1:36:03:48"
],
[
"oo",
"5",
"24:df:6a:e7:47:3c",
"e8:de:27:5b:a2:ea",
"70:8b:cd:b3:17:2c",
"f4:f2:6d:d1:20:20",
"e8:50:8b:f3:a9:2a"
]
]
**客户代码:**(接收实体)
public class databrowsing extends AppCompatActivity {
Socket myclient = null;
private String jsonString = "";
Gson gson = new Gson();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_databrowsing);
socketHandler CLIENT = new socketHandler();
myclient = CLIENT.getSocket();
PrintWriter pw = null;
try {
pw = new PrintWriter(myclient.getOutputStream(), true);
} catch (IOException e) {
e.printStackTrace();
}
pw.println("OnlinePositiongforIndoorPositioning");
new receiveJson().execute(myclient);
}
private class receiveJson extends AsyncTask< Socket,Void,String> {
@Override
protected String doInBackground(Socket... params ){
myclient=params[0];
try {
StringBuffer buildString=new StringBuffer();
BufferedReader in = new BufferedReader(new InputStreamReader(myclient.getInputStream()));
while((jsonString=in.readLine())!=null){
buildString.append(jsonString);
}
return jsonString;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
String[][] tableconfig = gson.fromJson(jsonString, String[][].class);
System.out.println(Arrays.deepToString(tableconfig));
}
}
Android Studio的错误Logcat:
java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)
at libcore.io.IoBridge.maybeThrowAfterRecvfrom(IoBridge.java:545)
at libcore.io.IoBridge.recvfrom(IoBridge.java:509)
at java.net.PlainSocketImpl.read(PlainSocketImpl.java:488)
at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:46)
at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:240)
at java.io.InputStreamReader.read(InputStreamReader.java:233)
at java.io.BufferedReader.fillBuf(BufferedReader.java:145)
at java.io.BufferedReader.readLine(BufferedReader.java:397)
at com.utm.jeechunhian.indoorpositioning.databrowsing$receiveJson$override.doInBackground(databrowsing.java:53)
at com.utm.jeechunhian.indoorpositioning.databrowsing$receiveJson$override.access$dispatch(databrowsing.java)
at com.utm.jeechunhian.indoorpositioning.databrowsing$receiveJson.doInBackground(databrowsing.java:0)
at com.utm.jeechunhian.indoorpositioning.databrowsing$receiveJson.doInBackground(databrowsing.java:44)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: libcore.io.ErrnoException: recvfrom failed: ECONNRESET (Connection reset by peer)
at libcore.io.Posix.recvfromBytes(Native Method)
at libcore.io.Posix.recvfrom(Posix.java:141)
at libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:164)
at libcore.io.IoBridge.recvfrom(IoBridge.java:506)