-
2016-09-21 21:03:57
之前有掌握到了局域网内UDP通信技术,当时就有点蠢蠢欲动,想写个聊天的软件。后来软件工程课,老师让写一个小程序,就把这个完成了。
ChatActivity.java 聊天activity
import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.InetAddress; import java.net.SocketException; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import android.app.Activity; import android.app.ActivityManager; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; import com.example.androidtest.R; import com.example.ccjutils.Constant; import com.example.ccjutils.Request; import com.example.ccjutils.RequestDecode; import com.example.ccjutils.Response; public class ChatActivity extends Activity implements OnClickListener{ private TextView myTitle; private ListView myListView ; private String str,sex; private EditText sendMsg; private Button sendBtn; private MyAdapter adapter; List<Map<String, String>> data ; Map<String,String> map,map1 ; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_chat); SysApplication.getInstance().addActivity(this); receiveListen(); initView(); Intent intent = getIntent(); str = intent.getStringExtra("name"); sex = intent.getStringExtra("sex"); } private void receiveListen() { Thread thread = new Thread(new Listener(8080)); thread.start(); } private void initView() { data = new ArrayList<Map<String,String>>(); sendMsg = (EditText)findViewById(R.id.send_et); sendBtn = (Button)findViewById(R.id.send_btn); adapter = new MyAdapter(this); myTitle=(TextView)findViewById(R.id.title_tv); myListView = (ListView)findViewById(R.id.listView1); myListView.setSelection(myListView.getBottom()); myListView.setAdapter(adapter); myTitle.setText(R.string.chatroom); sendBtn.setOnClickListener(this); } @Override public void onClick(View v) { switch(v.getId()){ case R.id.send_btn: doSendButton();break; } } private void doSendButton() { if(sendMsg.length() == 0){ DisplayToast("发送消息不能为空!"); return; } else { map = new HashMap<String, String>(); map.put("myName", str); map.put("mySex",sex); map.put("myMsg", sendMsg.getText().toString()); data.add(map); Thread thread = new Thread(new sendMsg(map)); thread.start(); } Message msg = new Message(); msg.what = 1; myHandler.sendMessage(msg); sendMsg.setText(""); } private void DisplayToast(String str){ Toast toast = Toast.makeText(this, str, Toast.LENGTH_SHORT); toast.setGravity(Gravity.BOTTOM, 0, 220); toast.show(); } Handler myHandler = new Handler() { @Override public void handleMessage(Message msg) { if(msg.what == 1){ if(sex.equals("male")){ adapter.mySex = true; }else{ adapter.mySex = false; } adapter.count++; adapter.notifyDataSetChanged(); return; } else if(msg.what == 0){ adapter.count++; adapter.notifyDataSetChanged(); return; } } }; class sendMsg implements Runnable { Request myRequest = new Request(); Map<String,String> map ; public sendMsg(Map<String,String> map) { this.map = map; } @Override public void run() { try { myRequest.send(Constant.MESSAGE+";"+map.get("myName")+";"+map.get("mySex")+";"+map.get("myMsg")+";!", InetAddress.getByName("255.255.255.255"), 8080); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (SocketException e) { e.printStackTrace(); } catch (UnknownHostException e) { e.printStackTrace(); } } } /** * 监听端口类 * @author 程长江 * */ class Listener implements Runnable{ private Response myResponse; private RequestDecode myDecode; private int port;//监听端口 private boolean flag =true;//循环标志 public Listener(int port){ this.port = port; } /** * 循环接收port端口的请求 */ @Override public void run() { while(flag){ initData(); try { myResponse.receive(port); myDecode.decode(myResponse.data); responseRun(myDecode.response); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } } private void responseRun(ArrayList<String> response) throws IOException, InterruptedException { if(response.get(0).equals(Constant.MESSAGE)&&!response.get(1).equals(str)){ map1 = new HashMap<String, String>(); map1.put("otherName", response.get(1)); map1.put("otherSex", response.get(2)); map1.put("otherMsg", response.get(3)); data.add(map1); Message msg = new Message(); msg.what = 0; myHandler.sendMessage(msg); } } private void initData() { myDecode = new RequestDecode(); myResponse = new Response(); } } class MyAdapter extends BaseAdapter{ private LayoutInflater mInflater = null; private boolean mySex = true; int count = 0; public MyAdapter(Context context) { this.mInflater = LayoutInflater.from(context); } @Override public int getCount() { return count; } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return 0; } @Override public boolean areAllItemsEnabled() { return false; } @Override public boolean isEnabled(int position) { return false; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = null; if(data.get(position).get("myName") != null){ // if(convertView == null){ convertView = LayoutInflater.from(getApplicationContext()).inflate( R.layout.send_mode, null); holder = new ViewHolder(); holder.name = (TextView)convertView.findViewById(R.id.chat_person_send); holder.content = (TextView) convertView.findViewById(R.id.chat_content_send); holder.person = (ImageView)convertView.findViewById(R.id.img_send); convertView.setTag(holder); if(mySex){ holder.person.setImageResource(R.drawable.male); }else{ holder.person.setImageResource(R.drawable.female); } holder.name.setText(data.get(position).get("myName")); holder.content.setText(data.get(position).get("myMsg")); // } // else{ // holder = (ViewHolder)convertView.getTag();//取出ViewHolder对象 // } } else{ // if(convertView == null){ convertView = LayoutInflater.from(getApplicationContext()).inflate( R.layout.receive_mode, null); holder = new ViewHolder(); holder.name = (TextView)convertView.findViewById(R.id.person_receive); holder.content = (TextView) convertView.findViewById(R.id.content_receive); holder.person = (ImageView)convertView.findViewById(R.id.img_receive); convertView.setTag(holder); if(data.get(position).get("otherSex").equals("male")){ holder.person.setImageResource(R.drawable.male); }else{ holder.person.setImageResource(R.drawable.female); } holder.name.setText(data.get(position).get("otherName")); holder.content.setText(data.get(position).get("otherMsg")); // } // else{ // holder = (ViewHolder)convertView.getTag();//取出ViewHolder对象 // } } return convertView; } } @Override public void onBackPressed() { leave(); } /** * 弹窗 */ public void leave() { AlertDialog.Builder dialog=new AlertDialog.Builder(ChatActivity.this); dialog.setTitle("您真的要离开吗?").setPositiveButton("退出", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { SysApplication.getInstance().exit(); } }).setNegativeButton("取消", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel();//取消弹出框 } }).create().show(); } /**存放控件*/ public final class ViewHolder{ private TextView name; private ImageView person; private TextView content; } }
MainActivity.java 首界面
SysApplication.java 基础applicationimport java.io.UnsupportedEncodingException; import java.net.InetAddress; import java.net.SocketException; import java.net.UnknownHostException; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Gravity; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.RadioButton; import android.widget.Toast; import com.example.androidtest.R; import com.example.ccjutils.Constant; import com.example.ccjutils.Request; public class MainActivity extends Activity implements OnClickListener{ private Button adminBtn; private RadioButton male,female; private EditText nameEt; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); SysApplication.getInstance().addActivity(this); initView(); } private void initView() { adminBtn = (Button)findViewById(R.id.btn_login); nameEt = (EditText)findViewById(R.id.editText1); male = (RadioButton)findViewById(R.id.rbtn_male); female = (RadioButton)findViewById(R.id.rbtn_female); adminBtn.setOnClickListener(this); male.setOnClickListener(this); female.setOnClickListener(this); } @Override public void onClick(View v) { switch(v.getId()){ case R.id.btn_login: if(nameEt.length() == 0){ DisplayToast("昵称不能为空!"); return; } else if(nameEt.length()>10){ DisplayToast("建议昵称不超过10个字节"); return; } Intent intent = new Intent(MainActivity.this,ChatActivity.class); intent.putExtra("name",nameEt.getText().toString()); if(male.isChecked()){ intent.putExtra("sex","male"); } else{ intent.putExtra("sex", "female"); } startActivity(intent); break; case R.id.rbtn_male: male.setChecked(true); female.setChecked(false); break; case R.id.rbtn_female: male.setChecked(false); female.setChecked(true); break; default:break; } } private void DisplayToast(String str){ Toast toast = Toast.makeText(this, str, Toast.LENGTH_SHORT); toast.setGravity(Gravity.BOTTOM, 0, 220); toast.show(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }
import java.util.LinkedList; import java.util.List; import android.app.Activity; import android.app.Application; public class SysApplication extends Application { private List<Activity> mList = new LinkedList<Activity>(); private static SysApplication instance; private SysApplication() { } public synchronized static SysApplication getInstance() { if (null == instance) { instance = new SysApplication(); } return instance; } // add Activity public void addActivity(Activity activity) { mList.add(activity); } public void exit() { try { for (Activity activity : mList) { if (activity != null) activity.finish(); } } catch (Exception e) { e.printStackTrace(); } finally { System.exit(0); } } public void onLowMemory() { super.onLowMemory(); System.gc(); } }
Constant.java 通信常量
Request.java 请求类/** * 常量概览 * @author 程长江 * */ public class Constant { public static final String MESSAGE = "Message" ; }
RequestDecode.java 请求解码类 (我的编码解码命令就是用的";"号分割"!"结束)import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.InetAddress; import java.net.SocketException; /** * 请求发送类 * @author 程长江 * */ public class Request { /** * 发送函数 :参数为 所发命令command,目的ip地址,使用端口号port。 * @param command * @param ip * @param port * @throws UnsupportedEncodingException * @throws SocketException * @throws IOException */ public void send(String command, InetAddress ip,int port) throws UnsupportedEncodingException, SocketException { DatagramPacket dp = new DatagramPacket(command.getBytes("UTF-8"), command.getBytes("UTF-8").length, ip, port); System.out.println(ip); DatagramSocket ds = new DatagramSocket(); Thread t = new Thread (new RequestRunnable(dp,ds)); t.start(); System.out.println("-->端口 "+port+" 发送命令:"+command); } } class RequestRunnable implements Runnable{ DatagramPacket dp; DatagramSocket ds; public RequestRunnable(DatagramPacket dp,DatagramSocket ds){ this.dp = dp; this.ds = ds; } @Override public void run() { try { ds.send(dp); } catch (IOException e) { e.printStackTrace(); } ds.close(); } }
Response.java 响应类import java.util.ArrayList; /** * 请求解码类 * @author 程长江 * */ public class RequestDecode { public String content ; public ArrayList<String> response = new ArrayList<String>(); public static final char ENDCOMMAND = '!'; public static final char NODECOMMAND = ';'; public void decode(String data) throws Exception{ int beginIndex = 0; int endIndex = 0; while(endIndex <= data.length() && data.charAt(endIndex) != ENDCOMMAND){ if(data.charAt(endIndex) == NODECOMMAND){ content = data.substring(beginIndex, endIndex); System.out.println("content="+content); response.add(content); beginIndex = endIndex+1; } endIndex++; } System.out.println("response = "+response); } }
activity_chat.xml 交流界面import java.io.IOException; import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.InetAddress; /** * 响应接收类 * @author 程长江 * */ public class Response { public InetAddress ip = null; public String data; /** * 接收函数 :开启所传参数端口的接收端 * @param port * @throws IOException */ public void receive(int port) throws IOException { System.out.println("-->开启接收端口:"+port); DatagramSocket ds = new DatagramSocket(port); byte[] buf = new byte[1024]; DatagramPacket dp = new DatagramPacket(buf, buf.length); ds.receive(dp); ip = dp.getAddress(); data = new String(dp.getData(),0,dp.getLength(),"UTF-8"); ds.close(); System.out.println("-->ip:"+ip+"\n-->内容:"+data); System.out.println("-->端口"+port+": 接收成功"); } }
activity_main.xml 主界面<?xml version="1.0" encoding="UTF-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff" > <include android:id="@+id/include1" layout="@layout/title_mode" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:orientation="horizontal" android:id="@+id/ll" android:weightSum="5" > <EditText android:id="@+id/send_et" android:layout_width="200dp" android:layout_height="wrap_content" android:layout_weight="4.5" /> <Button android:id="@+id/send_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="0.5" android:background="@drawable/selector" android:text="发送" /> </LinearLayout> <ListView android:id="@+id/listView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_above="@+id/ll" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:stackFromBottom="true" android:layout_below="@+id/include1" android:transcriptMode="alwaysScroll" android:divider="#00000000"> </ListView> </RelativeLayout>
receive_mode.xml 接收消息的自定义mode<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/rootview" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/background" android:clickable="true" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.activity.MainActivity" > <TextView android:id="@+id/textView1" android:layout_width="match_parent" android:layout_height="40dp" android:gravity="center_horizontal" android:text="输入昵称" android:textColor="#000000" android:textSize="16sp" /> <requestFocus /> <Button android:id="@+id/btn_login" android:layout_width="200dp" android:layout_height="40dp" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:background="@drawable/selector" android:text="@+string/button_login" android:textColor="#F0FFFF" /> <RadioButton android:id="@+id/rbtn_male" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/btn_login" android:layout_alignLeft="@+id/btn_login" android:layout_marginBottom="33dp" android:checked="true" android:text="男" /> <EditText android:id="@+id/editText1" android:layout_width="match_parent" android:layout_height="40dp" android:layout_alignParentRight="true" android:layout_below="@+id/textView1" android:layout_weight="0.89" android:ems="10" android:paddingLeft="15dp" android:paddingRight="0dp" android:singleLine="true" android:textColorHint="#999999" android:textSize="18sp" /> <RadioButton android:id="@+id/rbtn_female" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/rbtn_male" android:layout_alignBottom="@+id/rbtn_male" android:layout_alignRight="@+id/btn_login" android:text="女" /> </RelativeLayout>
send_mode.xml 发送消息的自定义mode<?xml version="1.0" encoding="UTF-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/content_receive" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_toRightOf="@+id/ll" android:background="@drawable/receivebg" android:text="测试内容" android:textColor="#000000" android:textSize="@dimen/msg_size" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/ll" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:orientation="vertical" > <TextView android:id="@+id/person_receive" android:layout_width="60dp" android:layout_height="wrap_content" android:gravity="center_horizontal" android:text="自己" android:textSize="@dimen/name_size" /> <ImageView android:id="@+id/img_receive" android:layout_width="60dp" android:layout_height="60dp" android:layout_alignParentRight="true" android:gravity="center_horizontal" android:scaleType="fitXY" android:src="@drawable/default_head" /> </LinearLayout> </RelativeLayout>
<?xml version="1.0" encoding="UTF-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/chat_content_send" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_toLeftOf="@+id/l" android:background="@drawable/sendbg" android:text="测试内容" android:textColor="#000000" android:textSize="@dimen/msg_size" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/l" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:orientation="vertical" > <TextView android:id="@+id/chat_person_send" android:layout_width="60dp" android:layout_height="wrap_content" android:gravity="center_horizontal" android:text="自己" android:textSize="@dimen/name_size" /> <ImageView android:id="@+id/img_send" android:layout_width="60dp" android:layout_height="60dp" android:layout_alignParentRight="true" android:gravity="center_horizontal" android:scaleType="fitXY" android:src="@drawable/default_head" /> </LinearLayout> </RelativeLayout>
title_mode.xml 标题栏mode
AndroidManifest.xml<?xml version="1.0" encoding="UTF-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="35dp" android:background="@drawable/titlebg"> <TextView android:id="@+id/title_tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:gravity="center_horizontal" android:textColor="#ffffff" android:textSize="18sp" /> </RelativeLayout>
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.androidtest" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="11" android:targetSdkVersion="23" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" /> <uses-permission android:name="android.permission.RESTART_PACKAGES"></uses-permission> <application android:allowBackup="true" android:icon="@drawable/app_icon" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar" > <activity android:name="com.example.ccjclient.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="com.example.ccjclient.ChatActivity"></activity> </application> </manifest>
由于技术有限,这个软件可能有很多不合理的地方,毕竟纯练手。包含了一些Android开发的知识点,自己给自己mark一下。
这个app实现了同一局域网内android手机之间的聊天。(利用udp传输的广播机制,有listview的优化)PS:刚刚开始没优化时,卡到爆炸~~zzz
更多相关内容 -
基于QT的局域网聊天软件开发(文献综述)
2019-01-14 13:58:01基于QT与C++的局域网聊天软件开发的文献综述,希望可以帮到大家。 -
基于QT的局域网聊天软件开发(开题报告)
2019-01-14 13:51:19基于QT与C++的局域网聊天软件开发的开题报告,希望可以帮到大家。 -
Linpop局域网聊天软件开发过程文档
2016-01-14 18:09:20Linpop局域网聊天软件项目所有相关文档,包括个人日报、需求跟踪矩阵、概要设计、详细设计、开发人员配置表、答辩PPT、会议纪要 -
Qt开发的一款局域网聊天软件
2020-08-08 21:14:161. 资源是本人使用Qt5开发的一款局域网聊天软件,支持群聊、私聊、收发消息和文件,用户进入离开提示、查看局域网成员、界面换肤、多用户登录等; 2. 目前该软件不足的就是有很多小bug(程序还是可以正常运行的),... -
精选_基于Qt实现的局域网聊天系统_源码打包
2022-03-09 13:29:25基于Qt实现的局域网聊天系统 -
C#winform开发的局域网聊天程序
2021-09-25 17:05:31实现了不同客户端之间互相收发信息的功能 -
Android开发的局域网内聊天APP
2018-06-25 14:53:38Android开发的局域网内聊天APP,局域网内不仅可以进行文字聊天,还可以进行视频聊天 -
android局域网聊天开发代码
2012-02-19 23:17:36类似飞秋的一个android局域网聊天的,从网上淘来的,学习学习! -
飞秋FeiQ(局域网聊天软件)插件开发指南.pdf
2021-11-07 03:22:01飞秋FeiQ(局域网聊天软件)插件开发指南.pdf -
飞秋FeiQ(局域网聊天软件)插件开发指南终稿.pdf
2022-02-09 15:57:29飞秋FeiQ(局域网聊天软件)插件开发指南终稿.pdf -
飞秋FeiQ(局域网聊天软件)二次开发文档整理.pdf
2022-02-09 15:57:24飞秋FeiQ(局域网聊天软件)二次开发文档整理.pdf -
linux局域网聊天工具(附带文档和源码参考)
2020-05-26 16:50:272.1 体会从需求理解出发,到软件概要设计,详细设计,编码,测试,发布的整个流程,熟悉软件开发的全部流程; 2.2 熟悉Linux操作系统下的C/C++应用程序开发环境,掌握linux系统下开发工具vi、gcc 和gdb的使用,以及... -
飞秋FeiQ(局域网聊天软件)二次开发文档终稿.pdf
2022-03-03 00:43:01飞秋FeiQ(局域网聊天软件)二次开发文档终稿.pdf -
局域网聊天软件JAVA毕业论文_uik聊天软件下载
2020-03-27 22:46:10指导教师 2013年4月 局域网聊天软件 商丘工学院毕业论文设计 PAGE II 摘 要 在网络越来越发达的今天人们对网络的依赖越来越多越来越离不开网络由此而产生的聊天工具越来越多例如国外的ICQ国内腾讯公司开发的OICQ基于... -
C#语言在VS2010下开发的局域网聊天软件(聊天及文件传输)
2012-01-16 10:04:18在VS2010下用C#语言开发的局域网聊天软件(聊天及文件传输),下载后及可局域网通信,类似于飞鸽,网络通信值得一看. -
局域网聊天软件设计与实现(Linux,C++,MySQL)
2021-02-05 13:38:25局域网聊天软件设计与实现(,C++,MySQL)(任务书,中期检查报告,外文翻译,毕业论文16000字,程序代码,MySQL数据库,答辩PPT)摘 要局域网聊天软件是在LINUX系统下运行的一个应用程序,程序用c++语言编写。本程序有如下功能...局域网聊天软件设计与实现(,C++,MySQL)(任务书,中期检查报告,外文翻译,毕业论文16000字,程序代码,MySQL数据库,答辩PPT)
摘 要
局域网聊天软件是在LINUX系统下运行的一个应用程序,程序用c++语言编写。本程序有如下功能:用户列表自动刷新、通过TCP通信协议进行消息收发、MYsql数据库保存用户名与密码。该设计是一个简单的局域网聊天软件,适用于企业内部和实验室使用,不与互联网进行数据交换,具有高速、安全等优势。
本文着重介绍下列内容:对用户上下线消息通知、聊天消息收发等进行数据解析;TCP网络编程,讲述用TCP 创建Client和Server以及收发数据的实现;最后对本设计的具体实现方法和设计实现流程进行讲解以及程序运行分析。
关键词: LINUX;TCP;Socket;Mysql数据库;C++
The Design And Implementation of The LAN Chat Software
Abstract
The LAN chat tool is An application under LINUX.The application written by C++ language.This program has the following functions: sending broadcast when login and exit,sending and receiving messages by the TCP communication protocol, using MYsql database to save chat messages. it is most often used to chat in enterprise and laboratory, it is working without data exchange from Internet,so it can transmit data high speed and security.
This paper focuses on the following contents: the user online and offline message notification, chat message send and receive data analysis; TCP network programming, here tells the method of using TCP to create client and Server to send and receive data;Finally introduce the design method and implementation process of my graduation design and running the application.
Keywords: LINUX;TCP/IP;Socket;Mysql database;C++
需求分析
本项目基于LINUX系统实现在局域网内的聊天软件,软件分为服务端和客户端,要实现的功能如下。
服务器端:
(1)能够正确的启动服务器。
(2)能够监听指定的端口,来等待用户的连接。
(3)客户端注册时能通过数据库验证用户的注册信息,并把注册结果返回给客户端。
(4)客户端登陆时能通过数据库验证用户的登陆信息,登陆成功后,把此用户的登录消息通知其他好友。
(5)登陆成功时,能够向新连接的用户发送已上线的用户名单。
(6)能够接收客户端的群聊消息请求,并能正确无误地处理请求,并把消息发送到所有已登录的客户端。
(7)能够接受客户端的私聊消息请求,并能正确无误地处理请求,并把消息发送到特定的客户端。
(8)当用户断开与服务器端地连接时,服务器能够把连接正确的断开,并把该用户退出的消息通知其他用户。
(9)能够正确的关闭服务器。
客户端:
(1)能够启动应用程序,并与服务器建立连接。
(2)登陆界面,能够把登录信息正确的发送到服务器。
(3)能够正确的处理服务器反馈的登结果信息。
(4)注册界面,能够把注册信息正确的发送到服务器。
(5)能够正确的处理服务器反馈的注册结果信息。
(6)登录以后,能够自动的更新用户列表。
(7)能够把群聊消息正确的发送到服务器。
(8)能够正确的把群聊消息显示到群聊界面。
(9)能够把私聊消息正确的发送到服务器。
(10)能够正确的把私聊消息显示到特定的聊天窗口。
(11)客户端退出时,能够把该用户的退出消息发送到服务器,并关闭所有聊天窗口。
硬件环境:
CPU:Inter(R) Core(TM) i5 2.67GHz
内存:2.00 GB
硬盘:500 G
软件环境:
操作系统:Ubuntu 12.0.4
应用软件:QT 5.0.2
目录
摘 要 i
Abstract ii
1 绪论 1
1.1 课题背景 1
1.2 目的和意义 1
1.3 研究现状 1
2 系统分析 3
2.1 系统理论基础 3
2.1.1 C/S架构 3
2.1.2 TCP 3
2.1.3 Socket 4
2.1.4 QT编程框架 6
2.2 可行性研究 10
2.3 需求分析 11
2.4 系统运行环境 11
3 系统设计 12
3.1 系统结构设计 12
3.2 客户端服务器功能设计 12
3.3 客户端设计 13
3.4 服务器端设计 14
3.5 群聊和私聊模块的设计 16
4 程序描述与详细描述 17
4.1 服务器端验证客户端的登录信息 17
4.1.1 功能及实现 17
4.1.2 技术概要 18
4.2 服务器端处理用户消息 20
4.2.1 功能及实现 20
4.2.2 技术概要 21
4.3 客户端读取服务器发送的数据 23
4.3.1 功能及实现 23
4.3.2 技术概要 25
4.4客户端用户列表的更新 25
5 系统实现 27
5.1 登录模块设计 27
5.2 注册模块设计 28
5.3 群聊模块设计 29
5.4 私聊模块设计 32
结论 34
参考文献 35
致谢 36
-
Java局域网聊天(类似QQ)源代码
2020-03-11 05:30:37本系统是基于Socket的聊天系统,采用客户机/服务器(C/S)的模式来设计,是一个三层的C/S结构,采用经典的MVC模式,利于今后的维护和扩展,整体利用了java语言的平台无关性等众多优点,主要采用Socket网络编程接口、多... -
基于Linux的局域网聊天软件设计与实现.pdf
2021-09-06 12:33:05基于Linux的局域网聊天软件设计与实现.pdf -
qt局域网聊天工具
2018-06-26 20:33:38本应用主要借鉴于课本《课本嵌入式软件开发》后的开源代码分享,主要使用qt实现了局域网的聊天功能。 -
qt课程设计报告_局域网聊天软件.rar
2020-05-02 16:06:12该资源为在校期间利用QT开发的局域网聊天软件,内附源码和实验报告,如有不妥之处,欢迎大家交流指导,谢谢! -
Linux下局域网聊天程序
2013-01-18 19:26:19一个在Linux下可以使用的聊天软件,Client/Server架构 -
JAVA局域网聊天软件 毕业论文讲解学习.doc
2020-04-05 15:06:18题目局域网聊天软件 系 院 学生姓名 学 号 专 业软件技术 指导教师 2013年4月 摘 要 在网络越来越发达的今天人们对网络的依赖越来越多越来越离不开网络由此而产生的聊天工具越来越多例如国外的ICQ国内腾讯公司开发的... -
局域网聊天系统(简易QQ)
2012-12-20 22:20:50简易局域网聊天系统 具体功能及界面展示见:http://blog.csdn.net/wudaijun/article/details/8351666 有非常详尽的注释,并且有系列Blog阐述开发流程 可在上面网址跟踪链接进入 如有不懂的地方或是您有好的见解也可... -
局域网聊天软件
2015-04-26 11:20:27eclipse开发平台 JAVA语言编写 JDK开发环境 基于C/S结构 -
精选_基于JAVA的局域网聊天软件的设计与实现(仿制QQ)_源码打包
2022-03-06 15:11:55基于JAVA的局域网聊天软件的设计与实现(仿制QQ) -
最新局域网聊天软件需求分析
2013-09-28 11:23:53而局域网聊天软件因其方便、安全,逐渐被人重 视,相应的聊天软件也如雨后春笋应运而生。我们设计的软件是以 JAVA 语言为 实现语言,期为用户提供一个界面友好、功能丰富、操作简单的局域网聊天软 件。 -
linux下的局域网聊天软件linpop
2013-09-24 13:32:47这是我在大连东软集团实习时做的项目,一个基于linux下的局域网聊天软件,采用了C/S结构,界面别具一格,并实现了文件传输功能,能实现消息离线传送、发送表情、文件传输等功能,开发工具为codeblocks和glade。 -
C#局域网聊天发送文件
2018-11-09 10:42:43C#开发的局域网聊天软件,可以进行发送消息,传输文件等常见操作。点开即可运行,不需要做任何配置。业务代码逻辑规范,注释完全 -
UDP局域网QQ聊天软件
2010-08-29 10:55:50用VS2005结合SQL Server数据库使用C#语言开发的一款在局域网内部进行通信的QQ聊天程序,包含客户端和服务器端;具有文本聊天、图片表情发送、文件传输、语音、视频聊天等功能,还将源程序打包成了安装源。