Home Database Mysql Tutorial C# 移动端与PC端的数据交互

C# 移动端与PC端的数据交互

Jun 07, 2016 pm 04:00 PM
c# oracle database

针对目前功能越来越强大的智能手机来说,在PC端支持对手机中的用户数据作同步、备份以及恢复等保护措施的应用已经急需完善。不仅

小记:针对目前功能越来越强大的智能手机来说,在PC端支持对手机中的用户数据作同步、备份以及恢复等保护措施的应用已经急需完善。不仅要对数据作保护,而且用户更希望自己的手机跟PC能够一体化,以及和远程服务器的一体化。用户希望在手机端的操作能够转移到PC端,对于PC端大屏幕的电脑来说,完成同样的操作可以大量的节省用户的时间。对于功能强大的手机来说,,有近1/2的应用可以在PC端同步。所以对PC端应用的规划要以系统的角度来对待。同时要保证手机端和PC端的主流交互模式应保持一致。个人观点:数据的一体化和管理的多元化是以后发展的一个趋势。下面进行今天的学习,今天的实验室移动端和PC端的数据交互及解析。

1,如何实现移动端和PC端的数据交互?

  答:1,蓝牙  2,NFC技术 3,红外 4,Socket.

C# 移动端与PC端的数据交互

NFC和蓝牙的异同点:

  相同点:都是近距离传输。

  不同点: NFC优于红外和蓝牙传输方式。作为一种面向消费者的交易机制,NFC比红外更快、更可靠而且简单得多,不用向红外那样必须严格的对齐才能传输数据。与蓝牙相比,NFC面向近距离交易,适用于交换财务信息或敏感的个人信息等重要数据;蓝牙能够弥补NFC通信距离不足的缺点,适用于较长距离数据通信。因此,NFC和蓝牙互为补充,共同存在。事实上,快捷轻型的NFC 协议可以用于引导两台设备之间的蓝牙配对过程,促进了蓝牙的使用。但是要实现远距离的数据传输那就只能用Socket了,

下面进行代码的分析:

首先在PC上建立服务端Server.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;
using System.Threading;

namespace TcpServer
{
    class Program
    {
        public static Socket serverSocket;
        static Thread threadSend;
        static Thread sendDataToClient;
        static int count = 1;
        static void Main(string[] args)
        {
            //确定端口号
            int port = 121;

            //设定连接IP
            string host = "192.168.1.100";

            //将IP地址字符串转化为IP地址实例
            IPAddress ip = IPAddress.Parse(host);

            //将网络端点表示为 IP 地址和端口号
            IPEndPoint ipe = new IPEndPoint(ip, port);

            //建立Socket
            //addressFamily 参数指定 Socket 类使用的寻址方案
            //socketType 参数指定 Socket 类的类型
            //protocolType 参数指定 Socket 使用的协议。
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            //socket与本地终结点建立关联
            socket.Bind(ipe);
            while (true)
            {
                //开始监听端口
                socket.Listen(0);

                Console.WriteLine("服务已开启,请等待....." + DateTime.Now.ToString() + DateTime.Now.Millisecond.ToString());

                //为新建的连接建立新的Socket目的为客户端将要建立连接
                serverSocket = socket.Accept();
                Console.WriteLine("连接已建立......" + DateTime.Now.ToString() + DateTime.Now.Millisecond.ToString());
                Console.WriteLine("客户端IP:"+serverSocket.RemoteEndPoint);
                string recStr =string.Empty;
                //定义缓冲区用于接收客户端的数据
                byte[] recbyte = new byte[1024];
               
                ReceiveData();
   
                sendDataToClient = new Thread(sendData);
                sendDataToClient.Start();

            }
        }

        public static void sendData()
        {
         
            while (true)
            {
                Console.WriteLine("send to client\n");
                //服务端给客户端回送消息
                string strSend = "Hello Android Client!" + DateTime.Now.Second;
                //string strSend = "HelloClient1HelloClient2HelloClient3HelloClient4HelloClient5HelloClient6HelloClient7HelloClient8HelloClient9HelloClient10HelloClient11HelloClien12HelloClien13HelloClien14HelloClien15HelloClient16";
                byte[] sendByte = new byte[1024];
                //将发送的字符串转换为byte[]
                sendByte = UTF8Encoding.UTF8.GetBytes(strSend);
                //服务端发送数据
             
                serverSocket.Send(sendByte, sendByte.Length, 0);
                Thread.Sleep(1000);
            }
        }

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

Why Use MySQL? Benefits and Advantages Why Use MySQL? Benefits and Advantages Apr 12, 2025 am 12:17 AM

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

How to create cursors in oracle loop How to create cursors in oracle loop Apr 12, 2025 am 06:18 AM

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

C# vs. C  : History, Evolution, and Future Prospects C# vs. C : History, Evolution, and Future Prospects Apr 19, 2025 am 12:07 AM

The history and evolution of C# and C are unique, and the future prospects are also different. 1.C was invented by BjarneStroustrup in 1983 to introduce object-oriented programming into the C language. Its evolution process includes multiple standardizations, such as C 11 introducing auto keywords and lambda expressions, C 20 introducing concepts and coroutines, and will focus on performance and system-level programming in the future. 2.C# was released by Microsoft in 2000. Combining the advantages of C and Java, its evolution focuses on simplicity and productivity. For example, C#2.0 introduced generics and C#5.0 introduced asynchronous programming, which will focus on developers' productivity and cloud computing in the future.

How to stop oracle database How to stop oracle database Apr 12, 2025 am 06:12 AM

To stop an Oracle database, perform the following steps: 1. Connect to the database; 2. Shutdown immediately; 3. Shutdown abort completely.

How to create oracle dynamic sql How to create oracle dynamic sql Apr 12, 2025 am 06:06 AM

SQL statements can be created and executed based on runtime input by using Oracle's dynamic SQL. The steps include: preparing an empty string variable to store dynamically generated SQL statements. Use the EXECUTE IMMEDIATE or PREPARE statement to compile and execute dynamic SQL statements. Use bind variable to pass user input or other dynamic values ​​to dynamic SQL. Use EXECUTE IMMEDIATE or EXECUTE to execute dynamic SQL statements.

What steps are required to configure CentOS in HDFS What steps are required to configure CentOS in HDFS Apr 14, 2025 pm 06:42 PM

Building a Hadoop Distributed File System (HDFS) on a CentOS system requires multiple steps. This article provides a brief configuration guide. 1. Prepare to install JDK in the early stage: Install JavaDevelopmentKit (JDK) on all nodes, and the version must be compatible with Hadoop. The installation package can be downloaded from the Oracle official website. Environment variable configuration: Edit /etc/profile file, set Java and Hadoop environment variables, so that the system can find the installation path of JDK and Hadoop. 2. Security configuration: SSH password-free login to generate SSH key: Use the ssh-keygen command on each node

From Web to Desktop: The Versatility of C# .NET From Web to Desktop: The Versatility of C# .NET Apr 15, 2025 am 12:07 AM

C#.NETisversatileforbothwebanddesktopdevelopment.1)Forweb,useASP.NETfordynamicapplications.2)Fordesktop,employWindowsFormsorWPFforrichinterfaces.3)UseXamarinforcross-platformdevelopment,enablingcodesharingacrossWindows,macOS,Linux,andmobiledevices.

See all articles