当前位置: 首页 > news >正文

胶州网站建设公司哪家好深圳网络推广公司哪家好

胶州网站建设公司哪家好,深圳网络推广公司哪家好,益保网做推广网站吗?,网站经营性备案多少钱这学期有个课设,我们组我负责一个手机APP的开发,虽然刚开始说要实现什么智能导航,类似高德地图那种,但最后阉割的只剩一个Socket通信了,因为之前没有接触过(可能之后也不会再接触),记…

这学期有个课设,我们组我负责一个手机APP的开发,虽然刚开始说要实现什么智能导航,类似高德地图那种,但最后阉割的只剩一个Socket通信了,因为之前没有接触过(可能之后也不会再接触),记录一下开发中遇到的问题。

1.开发工具:Andriod Studio,主要功能:实现与开发板的Socket通信,具体是手机端收到板子消息按钮变色或者文本框显示对应文字,手机端也会发送消息给板子,让板子跳转用户操作界面,整个就是一个简单的前端,逻辑不需要手机端处理。手机端只负责显示。
2.实现效果:
在这里插入图片描述
在这里插入图片描述

3.一些关键问题和收获:
1)andriod studio 的使用:
感觉还是比较复杂的,前期的一些环境配置有点忘了,按照提示做就可以,主要是手机运行环境的一些配置,然后之后在打包程序安装在手机上出了点问题,需要密钥,按网上指导就可以。
对自带模板的灵活使用:as自带很多模板,比如我开发的这个丑陋的app就是在bottom Navigation Activity这个现成模板的基础上进行开发的。
在这里插入图片描述
之前as排版的Xml文件,下载手机上就会变乱。后面不知不觉就好了,注意这个问题。
2)Socket通信:
这个是这个项目的一个主要工作,其中遇到的第一个问题,怎么创建Socket通信:

class ConnectThread extends Thread {public void run() {try {//新建Socketsocket = new Socket("192.168.4.1", 8086);System.out.println("创建Socket成功");} catch (IOException e) {e.printStackTrace();}}}

Socket的收发信息:注意Socket的收发信息或者说对网络的操作不能直接在主线程进行,一般都需要开子线程。
Socket的收信息:

final byte[] buffer = new byte[1024];//创建接收缓冲区try {inputStream = socket.getInputStream();System.out.println("Socket接收数据成功");} catch (IOException e) {e.printStackTrace();}int len = 0;//数据读出来,并且返回数据的长try {len = inputStream.read(buffer);System.out.println("接收数据大小" + len);} catch (IOException e) {e.printStackTrace();}//BUFFER 内容转为字符串String recvStr = new String(buffer, 0, len);

Socket的发信息:

 //控制子线程开始public void buttonFunc() {// 在主线程中需要发送数据的代码片断前插入// 阻塞主线程,使子线程按照“同步”的方式执行try {System.out.println("线程开始");new Thread(sendthread).start();    // 线程启动new Thread(sendthread).join();     // 线程加入执行队列,主线程被阻塞,等待子线程执行完毕} catch (Exception e) {e.printStackTrace();System.out.println(e.toString());}}// 发送数据子线程final Runnable sendthread = new Runnable() {@Overridepublic void run() {try {System.out.println("发送数据的子线程执行中");try {try {//输出流初始化outputStream = socket.getOutputStream();System.out.println("outputStream创建成功");} catch (IOException e) {e.printStackTrace();}try {//写入数据outputStream.write(sendbuf);outputStream.flush();System.out.println("数据写入成功");} catch (IOException e) {e.printStackTrace();}} catch (Exception e) {e.printStackTrace();}System.out.println("数据发送成功,子线程执行完毕");} catch (Exception e) {e.printStackTrace();System.out.println("子线程:"+ e.toString());}}};

socket的数据解析及数据格式:
收信息需要先转换为string类型,发信息如果要发16进制,byte数组直接写成16进制的形式。

源码:
美食城:

package com.example.parkingassitant2.ui.home;import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;import com.example.parkingassitant2.databinding.FragmentHomeBinding;import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;public class HomeFragment extends Fragment {private FragmentHomeBinding binding;//发送数据保存byte[] sendbuf = {(byte) 0xaa, (byte) 0xaa,0x03, (byte) 0x12,0x03,0x18, (byte) 0xaa};Socket socket = null;        //定义socketOutputStream  outputStream = null;    //定义输出流(发送)public View onCreateView(@NonNull LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState) {HomeViewModel homeViewModel =new ViewModelProvider(this).get(HomeViewModel.class);binding = FragmentHomeBinding.inflate(inflater, container, false);View root = binding.getRoot();ConnectThread ct;ct = new ConnectThread();ct.start();//江底捞final Button jiangdilao = binding.xiaocaiyuan;//湖底捞按钮final Button hudilao = binding.A2;//河底捞按钮final Button hedilao = binding.B1;//海底捞按钮final Button haidilao = binding.B2;//KFC按钮final Button KFC = binding.C1;//小菜园按钮final Button xiaocaiyuan = binding.C2;//万达影城按钮final Button wanda = binding.D1;//星巴克按钮final Button starbuck = binding.D2;//江底捞按钮监听函数jiangdilao.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {//不同按钮对应不同的数据流sendbuf = new byte[]{(byte) 0xaa, (byte) 0xaa, 0x03, (byte) 0x12, 0x03, 0x18, (byte) 0xaa};buttonFunc();Toast.makeText(getContext(), "预约成功,请更新停车场信息!", Toast.LENGTH_SHORT).show();}});//湖底捞按钮监听函数hudilao.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {//不同按钮对应不同的数据流sendbuf = new byte[]{(byte) 0xaa, (byte) 0xaa, 0x03, (byte) 0x21, 0x03, 0x27, (byte) 0xaa};buttonFunc();Toast.makeText(getContext(), "预约成功,请更新停车场信息!", Toast.LENGTH_SHORT).show();}});//河底捞按钮监听函数hedilao.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {//不同按钮对应不同的数据流sendbuf = new byte[]{(byte) 0xaa, (byte) 0xaa, 0x03, (byte) 0x22, 0x03, 0x28, (byte) 0xaa};buttonFunc();Toast.makeText(getContext(), "预约成功,请更新停车场信息!", Toast.LENGTH_SHORT).show();}});//海底捞按钮监听函数haidilao.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {//不同按钮对应不同的数据流sendbuf = new byte[]{(byte) 0xaa, (byte) 0xaa, 0x03, (byte) 0x11, 0x03, 0x17, (byte) 0xaa};buttonFunc();Toast.makeText(getContext(), "预约成功,请更新停车场信息!", Toast.LENGTH_SHORT).show();}});//小菜园按钮监听函数xiaocaiyuan.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {//不同按钮对应不同的数据流sendbuf = new byte[]{(byte) 0xaa, (byte) 0xaa, 0x03, (byte) 0x13, 0x03, 0x19, (byte) 0xaa};buttonFunc();Toast.makeText(getContext(), "预约成功,请更新停车场信息!", Toast.LENGTH_SHORT).show();}});//星巴克按钮监听函数starbuck.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {//不同按钮对应不同的数据流sendbuf = new byte[]{(byte) 0xaa, (byte) 0xaa, 0x03, (byte) 0x14, 0x03, 0x1a, (byte) 0xaa};buttonFunc();Toast.makeText(getContext(), "预约成功,请更新停车场信息!", Toast.LENGTH_SHORT).show();}});//肯德基按钮监听函数KFC.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {//不同按钮对应不同的数据流sendbuf = new byte[]{(byte) 0xaa, (byte) 0xaa, 0x03, (byte) 0x23, 0x03, 0x29, (byte) 0xaa};buttonFunc();Toast.makeText(getContext(), "预约成功,请更新停车场信息!", Toast.LENGTH_SHORT).show();}});//电影院按钮监听函数wanda.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {//不同按钮对应不同的数据流sendbuf = new byte[]{(byte) 0xaa, (byte) 0xaa, 0x03, (byte) 0x24, 0x03, 0x2a, (byte) 0xaa};buttonFunc();Toast.makeText(getContext(), "预约成功,请更新停车场信息!", Toast.LENGTH_SHORT).show();}});return root;}class ConnectThread extends Thread {public void run() {try {//两个不同IP地址。网络助手和板子//socket = new Socket("192.168.71.1", 8086);//新建Socketsocket = new Socket("192.168.4.1", 8086);System.out.println("创建Socket成功");} catch (IOException e) {e.printStackTrace();}}}@SuppressLint("SuspiciousIndentation")@Overridepublic void onDestroyView() {super.onDestroyView();binding = null;try {if(socket != null) {socket.close();}} catch (IOException e) {e.printStackTrace();}}//控制子线程开始public void buttonFunc() {// 在主线程中需要发送数据的代码片断前插入// 阻塞主线程,使子线程按照“同步”的方式执行try {System.out.println("线程开始");new Thread(sendthread).start();    // 线程启动new Thread(sendthread).join();     // 线程加入执行队列,主线程被阻塞,等待子线程执行完毕} catch (Exception e) {e.printStackTrace();System.out.println(e.toString());}}// 发送数据子线程final Runnable sendthread = new Runnable() {@Overridepublic void run() {try {System.out.println("发送数据的子线程执行中");try {try {//输出流初始化outputStream = socket.getOutputStream();System.out.println("outputStream创建成功");} catch (IOException e) {e.printStackTrace();}try {//写入数据outputStream.write(sendbuf);outputStream.flush();System.out.println("数据写入成功");} catch (IOException e) {e.printStackTrace();}} catch (Exception e) {e.printStackTrace();}System.out.println("数据发送成功,子线程执行完毕");} catch (Exception e) {e.printStackTrace();System.out.println("子线程:"+ e.toString());}}};
}

停车场:

package com.example.parkingassitant2.ui.dashboard;import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;import com.example.parkingassitant2.databinding.FragmentDashboardBinding;import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;public class DashboardFragment extends Fragment {private FragmentDashboardBinding binding;Socket socket = null;		//定义socketOutputStream outputStream = null;    //定义输入流(接收)public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {DashboardViewModel dashboardViewModel = new ViewModelProvider(this).get(DashboardViewModel.class);binding = FragmentDashboardBinding.inflate(inflater, container, false);View root = binding.getRoot();ConnectThread ct;ct = new ConnectThread();ct.start();return root;}class ConnectThread extends Thread{InputStream inputStream=null;	//定义输入流(接收)final Button A1 =binding.A1;final Button A2 = binding.A2;final Button D1 = binding.D1;public void run(){System.out.println(Thread.currentThread().getName()+": Hello");try {//socket = new Socket("192.168.71.1", 8086);socket = new Socket("192.168.4.1", 8086);binding.textView5.setText("连接成功");System.out.println("创建Socket成功");} catch (IOException e) {System.out.println("创建Socket失败");e.printStackTrace();}try{while (true){final byte[] buffer = new byte[1024];//创建接收缓冲区try {inputStream = socket.getInputStream();System.out.println("Socket接收数据成功");} catch (IOException e) {e.printStackTrace();}int len = 0;//数据读出来,并且返回数据的长try {len = inputStream.read(buffer);System.out.println("接收数据大小" + len);} catch (IOException e) {e.printStackTrace();}//BUFFER 内容转为字符串String recvStr = new String(buffer, 0, len);//找到读取开始处,一般为0int stadex = recvStr.indexOf("aaaa");System.out.println("解析数据开始位置" + stadex);int check_3,check_4,check_5,check_6;while(stadex < len){stadex = recvStr.indexOf("aaaa",stadex);int funcType_sta = stadex+4;int funcType_end = stadex+6;if(funcType_end > len || funcType_sta >= len){break;}//位置3是操作类型 02 是显示车牌预约停车场String pos3 = recvStr.substring(funcType_sta,funcType_end);// check_3 = Integer.parseInt(pos3);stadex = funcType_end;//停车预约功能中,位置4是车牌号String pos4 = recvStr.substring(stadex,stadex+2);//check_4 = Integer.parseInt(pos4);stadex += 2;//停车预约功能中,位置5是目的地String pos5 = recvStr.substring(stadex,stadex+2);//check_5 = Integer.parseInt(pos5);stadex += 2;String pos6 = recvStr.substring(stadex,stadex+2);//check_6 = Integer.parseInt(pos6);stadex += 2;//if( check_6 != check_3+check_4+check_5) break;stadex += 2;System.out.println("解析数据包" + "aaaa" + pos3 + pos4 + pos5 + pos6 + "aa");System.out.println("操作类型指示值:" + pos3);switch(pos3){case "01": {System.out.println("操作类型为欢迎车牌进站");String showText = null;switch (pos4) {case "01":showText = "欢迎京A00001";break;case "02":showText = "欢迎青ASB520";break;case "03":showText = "欢迎皖A66666";break;case "04":showText = "欢迎宁E88888";break;default:break;}binding.textView5.setText(showText);break;}case "04": {System.out.println("操作类型为停车预约");String showText = null;switch (pos4) {case "01":showText = "京A00001";break;case "02":showText = "青ASB520";break;case "03":showText = "皖A66666";break;case "04":showText = "宁E88888";break;default:break;}String address = null;switch (pos5){case "11":address = "海底捞";break;case "12":address = "江底捞";break;case "13":address = "小菜园";break;case "14":address = "星巴克";break;case "21":address = "湖底捞";break;case "22":address = "河底捞";break;case "23":address = "肯德基";break;case "24":address = "电影院";break;case "a1":address = "A1";break;case "a2":address = "A2";break;case "d1":address = "D1";break;default:break;}binding.textView5.setText(showText+"车主预约车位:" + address);break;}case "03": {System.out.println("操作类型为车位状态变更");switch (pos4) {case "a1": {if (pos5.equals("00")) {binding.A1.setBackgroundColor(Color.parseColor("#00FF00"));} else if (pos5.equals("01")) {binding.A1.setBackgroundColor(Color.parseColor("#FF0000"));} else if (pos5.equals("02")) {binding.A1.setBackgroundColor(Color.parseColor("#FFFF00"));}break;}case "a2": {System.out.println("pos5: ");System.out.println(pos5);if (pos5.equals("00")) {binding.A2.setBackgroundColor(Color.parseColor("#00FF00"));} else if (pos5.equals("01")) {binding.A2.setBackgroundColor(Color.parseColor("#FF0000"));} else if (pos5.equals("02")) {binding.A2.setBackgroundColor(Color.parseColor("#FFFF00"));}break;}case "d1": {if (pos5.equals("00")) {binding.D1.setBackgroundColor(Color.parseColor("#00FF00"));} else if (pos5.equals("01")) {binding.D1.setBackgroundColor(Color.parseColor("#FF0000"));} else if (pos5.equals("02")) {binding.D1.setBackgroundColor(Color.parseColor("#FFFF00"));}break;}default:break;}}default:break;}}}} catch (Exception ex) {ex.printStackTrace();}}}@SuppressLint("SuspiciousIndentation")@Overridepublic void onDestroyView() {super.onDestroyView();try {if(socket != null) {socket.close();}} catch (IOException e) {e.printStackTrace();}binding = null;}
}

文章转载自:
http://strain.bnpn.cn
http://demagoguery.bnpn.cn
http://fibrillate.bnpn.cn
http://premiss.bnpn.cn
http://dahlak.bnpn.cn
http://linzertorte.bnpn.cn
http://ahf.bnpn.cn
http://hiragana.bnpn.cn
http://sough.bnpn.cn
http://catachresis.bnpn.cn
http://becoming.bnpn.cn
http://martinmas.bnpn.cn
http://aftertax.bnpn.cn
http://seastar.bnpn.cn
http://impennate.bnpn.cn
http://capsicin.bnpn.cn
http://leucotome.bnpn.cn
http://agitatedly.bnpn.cn
http://dopaminergic.bnpn.cn
http://embassy.bnpn.cn
http://marlene.bnpn.cn
http://america.bnpn.cn
http://goboon.bnpn.cn
http://alipterion.bnpn.cn
http://reportorial.bnpn.cn
http://pollinose.bnpn.cn
http://lithography.bnpn.cn
http://effector.bnpn.cn
http://leukodermal.bnpn.cn
http://underpaint.bnpn.cn
http://chastisable.bnpn.cn
http://tricuspid.bnpn.cn
http://clocker.bnpn.cn
http://celature.bnpn.cn
http://quemoy.bnpn.cn
http://arrear.bnpn.cn
http://reddle.bnpn.cn
http://disambiguate.bnpn.cn
http://kroon.bnpn.cn
http://officious.bnpn.cn
http://vesicant.bnpn.cn
http://dispenser.bnpn.cn
http://mhr.bnpn.cn
http://nevoid.bnpn.cn
http://dukawallah.bnpn.cn
http://iliamna.bnpn.cn
http://trunk.bnpn.cn
http://eleusinian.bnpn.cn
http://livingly.bnpn.cn
http://paleogene.bnpn.cn
http://exsect.bnpn.cn
http://styx.bnpn.cn
http://inanimate.bnpn.cn
http://tarlatan.bnpn.cn
http://excretive.bnpn.cn
http://spermatozoid.bnpn.cn
http://outswinger.bnpn.cn
http://griminess.bnpn.cn
http://indissociable.bnpn.cn
http://hyposarca.bnpn.cn
http://simular.bnpn.cn
http://curite.bnpn.cn
http://analytic.bnpn.cn
http://athrill.bnpn.cn
http://icequake.bnpn.cn
http://catalo.bnpn.cn
http://blindstory.bnpn.cn
http://dissoluble.bnpn.cn
http://glimpse.bnpn.cn
http://lauretta.bnpn.cn
http://payout.bnpn.cn
http://pda.bnpn.cn
http://susceptible.bnpn.cn
http://handicapped.bnpn.cn
http://miscast.bnpn.cn
http://headpin.bnpn.cn
http://orderliness.bnpn.cn
http://chronotron.bnpn.cn
http://fluidness.bnpn.cn
http://dichloride.bnpn.cn
http://paniculated.bnpn.cn
http://graven.bnpn.cn
http://katana.bnpn.cn
http://pistonhead.bnpn.cn
http://bridgework.bnpn.cn
http://mintmark.bnpn.cn
http://isoleucine.bnpn.cn
http://zeebrugge.bnpn.cn
http://maseru.bnpn.cn
http://chronobiology.bnpn.cn
http://pauper.bnpn.cn
http://demographer.bnpn.cn
http://adenoids.bnpn.cn
http://socialistically.bnpn.cn
http://kktp.bnpn.cn
http://bananalander.bnpn.cn
http://reenforce.bnpn.cn
http://cygnet.bnpn.cn
http://histiocytic.bnpn.cn
http://clocking.bnpn.cn
http://www.dt0577.cn/news/123355.html

相关文章:

  • 中国十大知名网站建设营销模式都有哪些
  • 做会员卡的网站在线制作网络营销策划师
  • 政府网站 两学一做比较有名的个人网站
  • 大气物流网站模块网络营销策略制定
  • 网站怎么做熊掌号百度关键词指数排行
  • 做类型网站查询网 域名查询
  • 电子商务网站建设的步骤过程鞍山seo优化
  • 简述对网站进行评析的几个方面.最新国际新闻50条简短
  • 江苏网站集约化建设吉林黄页电话查询
  • 加强对网站建设网页制作的步骤
  • 24手表网站海外网站cdn加速
  • web网站首页设计上海网络seo优化公司
  • 义乌网站建设公司b站黄页推广软件
  • 面包店网站功能建设与栏目划分宁波网站seo公司
  • 在线a视频网站一级a做片做个小程序需要花多少钱
  • 网站建设 做个网上商城要多少钱啊红河网站建设
  • 使用Elasticsearch做网站磁力链最佳的搜索引擎
  • 做网站需要填什么站牛网是做什么的
  • 深圳seo搜索优化北京网站seo公司
  • 徐州鼓楼区建设网站广州网站推广联盟
  • 网站制作jian she外贸网站模板
  • 米特号类似网站百中搜优化
  • 北京大兴专业网站建设公司公司做网站怎么做
  • excel做邮箱网站怎么加3www百度搜索引擎的优缺点
  • seo网站推广服务十大培训机构教育培训机构哪家好
  • 中国做外贸的网站谷歌广告
  • 广西做网站的公司关键词排名优化公司成都
  • 如何设计网站的主菜单个人网站推广平台大全
  • b2b商城网站系统南昌百度seo
  • 配送货wordpress济南网络seo公司