android wifi接收数据库,Android客户端通过WiFi从TCP服务器(ESP8266-12E)接收数据
目标简介:
1)启动ESP8266 Wifi模块作为侦听特定端口的TCP服务器 - >到目前为止完成
2)从服务器发送int或String到Client
2)编写一个作为客户端的Android应用程序(Android Studios),连接到服务器并接收发送的数据。
问题:
1)我的客户端应用程序没有收到任何数据
2)我也无法从我的MainActivity类访问消息以显示它在TextView中,变量处于Try,Catch Block中。
Android Studio
客户代码:
package com.example.petarmaric.client;
import android.util.Log;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.Socket;
/**
* Created by petarmaric on 04/02/2017.
*/
public class TCP_Client {
// Variables and Constants
public static final String SERVERIP = "192.168.1.2";
public static final int SERVERPORT = 3030;
DataInputStream in;
Integer serverMessage;
// Run the Client
public void run(){
try {
InetAddress serverAddress = InetAddress.getByName(SERVERIP);
Log.e("Connection", "connecting to server...");
//Create the Socket
Socket socket = new Socket(serverAddress, SERVERPORT);
Log.e("Socket", "Socket was created");
try {
//receive the message from the Server
//in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
in = new DataInputStream(socket.getInputStream());
Log.e("InputStream","DataInputStream created");
serverMessage = in.read();
Log.e("Message from Server", "Maybe");
} catch (Exception e) {
Log.e("InputERROR", "Nachricht wurde nicht empfangen");
} finally {
socket.close();
Log.e("Socket","Socket was closed");
}
}catch (Exception e){
Log.e("ConnectionERROR","Nicht connected");
}
Log.e("End","End of Run Method");
}
}应用程序启动后的Logcat:
Markdown and HTML are turned off in code blocks:
This is not italic, and this is not a link
02-04 18:36:17.475 25858-25858/com.example.petarmaric.client W/System: ClassLoader referenced unknown path: /data/app/com.example.petarmaric.client-2/lib/x86_64
02-04 18:36:17.788 25858-25858/com.example.petarmaric.client W/System: ClassLoader referenced unknown path: /data/app/com.example.petarmaric.client-2/lib/x86_64
02-04 18:36:18.157 25858-25858/com.example.petarmaric.client W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
02-04 18:36:18.213 25858-25895/com.example.petarmaric.client E/Connection: connecting to server...
02-04 18:36:18.217 25858-25896/com.example.petarmaric.client D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
[ 02-04 18:36:18.219 25858:25858 D/ ]
HostConnection::get() New Host Connection established 0x7fa68eb72bc0, tid 25858
[ 02-04 18:36:18.278 25858:25896 D/ ]
HostConnection::get() New Host Connection established 0x7fa68eb72e80, tid 25896
02-04 18:36:18.295 25858-25896/com.example.petarmaric.client I/OpenGLRenderer: Initialized EGL, version 1.4
02-04 18:36:18.367 25858-25895/com.example.petarmaric.client E/Socket: Socket was created
02-04 18:36:18.367 25858-25895/com.example.petarmaric.client E/InputStream: DataInputStream createdMainAcitvity代码:
Markdown and HTML are turned off in code blocks:
This is not italic, and this is not a link
package com.example.petarmaric.client;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends AppCompatActivity {
//Declaration of Client object
private TCP_Client mTcpClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Connect to the Server
new ConnectTask().execute("");
}
//ConnectClass definition
public class ConnectTask extends AsyncTask
{
@Override
protected TCP_Client doInBackground(Object[] params) {
//We create the TCP client object and run the Task
mTcpClient = new TCP_Client();
mTcpClient.run();
Log.e("Main Thread", "Client run initiated");
return null;
}
}
}Arduino IDE
ESP8266 12-E(Wifi模块代码):
#include
#include
#include
// declare the Variables
char* ssid = "NETGEAR54";
char* password = "calmpiano742";
char thisChar;
//create wifi server listen on a given port
WiFiServer server(3030);
//create Wifi client
WiFiClient client;
void setup() {
//Connnect to WiFi Network
Serial.begin(115200);
WiFi.begin(ssid,password);
Serial.println("");
//Wait for connection
while (WiFi.status()!=WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
//Print status to Serial Monitor
Serial.print("connected to: "); Serial.println(ssid);
Serial.print("IP Address: "); Serial.println(WiFi.localIP());
//Start the TCP server
server.begin();
}
void loop() {
client = server.available();
if(client){
if(client.connected()){
Serial.println("connected to client");
while(client.connected()){
server.write(1);
}
}
}
}串行监视器:
1384, room 16
tail 8
chksum ��
......connected to: NETGEAR54
IP Address: 192.168.1.2
connected to client
.....................................................................
Soft WDT reset
ctx: cont
sp: 3ffef2c0 end: 3ffef4f0 offset: 01b0
>>>stack>>>
3ffef470: 3ffe8644 3ffee49c 3ffee49c 40202d25
3ffef480: 3ffe8444 00000002 3ffe84ff 40203380
3ffef490: 00000001 3ffee388 3ffee49c 3ffee4c8
3ffef4a0: 3ffee388 3ffee49c 3ffee370 40201d40
3ffef4b0: 3ffe8480 00000000 000003e8 40201c89
3ffef4c0: 00000000 3fff0424 00000001 40202fc9
3ffef4d0: 3fffdad0 00000000 3ffee4c0 40202ff4
3ffef4e0: feefeffe feefeffe 3ffee4d0 40100718
<<
ets Jan 8 2013,rst cause:2, boot mode:(1,7)如果您需要更多信息,请提前感谢您的帮助,请在下面写下您的问题。
android wifi接收数据库,Android客户端通过WiFi从TCP服务器(ESP8266-12E)接收数据相关推荐
- android读取excel数据库,Android 读取Excel数据并保存在本地数据库
在工作中遇到需要将Excel的数据读取出来并保存在本地数据库中的操作,数据如下: 图片.png 需要做以下准备: 读取Excel的jar包[文章末尾会分享该jar包] 保存数据的数据库框架,在这里我们 ...
- android代码关闭数据库,android – 我应该如何正确打开和关闭我的数据库
我有一个应用程序,它将一些数据存储在SQLite数据库中.此外,我在我的应用程序中进行了大量查询和重新查询.我在其中有大约15个活动.并且所有人都使用数据库来查询数据. 但我正在做的是在每个活动中打开 ...
- android sqlite加密数据库,Android Sqlite数据库加密
Android使用的是开源的SQLite数据库,数据库本身没有加密,加密思路通常有两个: 1. 对几个关键的字段使用加密算法,再存入数据库 2. 对整个数据库进行加密 SQLite数据库加密工具: 收 ...
- android与mysql数据库同步_android开发 如何通过web服务器访问MYSQL数据库并且使其数据同步到android SQLite数据库?...
通过web服务器访问MYSQL数据库有以下几个过程: 1.在MySql下创建自己的数据库和自己的表单 2.连接数据库. 3.访问数据库 1.创建web工程 (服务器端) 在Myeclipse下新建一个 ...
- android代码打开数据库,Android打开和关闭数据库
与计算机编程中的许多事情一样,关闭SQLite数据库的时间没有单一的"正确进行"(如果您正在使用它,则通过SQLiteOpenHelper上的close(),否则对SQLiteDa ...
- android代码打开数据库,android – 如何正确关闭并重新打开Room数据库
您好我有2个应用程序依赖于制作和恢复应用程序数据库的备份,只需将数据库文件复制到SD卡中,然后很难确定如何在关闭它之后重新打开Room Database单例以创建数据库'副本. 构建数据库: @Dat ...
- android打开sqlite数据库,Android:打开和关闭SQLite数据库
我正在开发和android应用程序,我经常使用它访问本地数据库.这个数据库可以从不同的therads访问,所以我对数据库有一个协调问题.我使用以下open()和close()方法.Android:打开 ...
- android读写access数据库,Android中利用远程Microsoft Access数据库应用程序
我写一个Android应用程序,它接受一个字符串,通过条码阅读器读取,然后当一个特定的按钮按下时,它会认为字符串发送到数据库将他们的价值设定为"库存"或"缺货" ...
- android拦截请求数据库,拦截所有App的网络请求并将需要的数据上传到属于你自己的服务器...
前提 : 有时会遇到这样的需求:将一些别人app上比较优质的内容,用到自己产品中.由于别人的app做了大量的参数加密, 我们获取不到加密规则,所以使用接口直接调用的方法就走不通. 本文就是要介绍使用逆 ...
最新文章
- [头脑风暴] 解读Docker Bridge网络模型
- 自动补足算法是什么_如何自定义Shell(Fish版)的自动补全规则?
- ds18b20温度转换指令_STM32接口DS18S20温度传感器
- Kotlin基础学习第3章—内置类型
- java 出栈_Java开发中巧妙使用链表来实现模拟栈的入栈出栈操作
- 宝塔控制面板配置Nginx 安全证书
- 拓端tecdat|Python用LSTM长短期记忆神经网络对不稳定降雨量时间序列进行预测分析
- 微信小程序云开发教程-WXML入门-常用组件和属性
- G面经prepare: BuyGoods
- dosbox使用教程
- jsp linux 一键安装包,JspStudy免费版|JspStudy(jsp环境一键安装包) v2016.01.01免费版_星星软件园...
- 哈夫曼编码详解——图解真能看了秒懂
- C++primer plus第六版课后编程题答案14.3(仅供参考)
- android 高仿 猿题库,猿题库(com.fenbi.android.gaozhong) - 9.17.2 - 应用 - 酷安
- 使用Console.log调试
- 全网最硬核 JVM TLAB 分析 1. 内存分配思想引入
- Tomcat的访问及修改端口号
- 王者荣耀微信哪个服务器人多,王者荣耀:微信区比QQ区人数多,哪区实力水平高?代练道出真相...
- jQuery 效果- 隐藏和显示
- XML 中的 xmlns 等属性的意义