【发布时间】:2016-05-26 23:31:18
【问题描述】:
我已经制作了基于 NodeMCU 的小型服务器。一切正常,当我从浏览器连接时,但问题开始了,当我尝试从 Android 应用程序 uisng OkHttp 或 Volley 连接时,我收到异常。 java.io.IOException:使用 OkHttp 的连接上的流意外结束, 使用 Volley 的 EOFException。
问题与此非常相似 EOFException after server responds,但没有找到答案。
ESP 服务器代码
srv:listen(80, function(conn)
conn:on("receive", function(conn,payload)
print(payload)
conn:send("<h1> Hello, NodeMCU.</h1>")
end)
conn:on("sent", function(conn) conn:close() end)
end)
Android 代码
final RequestQueue queue = Volley.newRequestQueue(this);
final String url = "http://10.42.0.17:80";
final StringRequest request = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
mTemperatureTextView.setText(response.substring(0, 20));
System.out.println(response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
System.out.println("Error + " + error.toString());
mTemperatureTextView.setText("That didn't work!");
}
}
);
mUpdateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
queue.add(request);
}
});
【问题讨论】:
标签: android lua android-volley okhttp esp8266