Windows Mobile (C#) - 在手机和 PC 之间进行通信 [英] Windows Mobile (C#) - Communicating between phone and PC

查看:44
本文介绍了Windows Mobile (C#) - 在手机和 PC 之间进行通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个项目,其中运行在手机上的程序需要与其连接的 PC 上运行的程序进行通信.理想情况下,我想使用 USB、WiFi 等任何方式进行通信.

I'm working on a project where a program running on the mobile phone needs to communicate with a program running on the PC it's connected to. Ideally, I'd like to use USB, WiFi, whatever to communicate.

这两个程序应该能够传达诸如电池寿命、短信等内容...但我可以稍后处理,我只需要让他们说话.

The two programs should be able to communicate things like battery life, text messages, etc... But I can work on that later, I just need to get them to talk.

最好的方法是什么?

推荐答案

最佳"确实是主观的,并且高度依赖于许多因素,例如设备、拓扑、防火墙存在、安全需求等.

"Best" is really subjective and highly dependent on a lot of factors like devices, topology, firewall presence, need for security, etc, etc.

您需要从何处发起通信?是否有 ActiveSync 连接?如果 PC 启动通信并且您拥有 ActiveSync,那么 RAPI 就是您要使用的传输方式,因为它已完成并准备好所有基础设施.

Where do you need the comms to originate and will you have an ActiveSync connection? If the PC initiates the comms and you have ActiveSync, then RAPI is the transport you'd use as it's got all of the infrastructure done and ready.

对于其他任何事情,您都需要某种形式的专有协议和传输机制.通常,我会编写一个简单的套接字协议,其中包含已定义的消息结构(通常是消息 ID、CRC、消息长度和数据负载).然后我有一些基本消息类来处理通信和一组我想要的每个特定命令的派生消息.对于需要响应的 2 路内容,我通常会创建一个基本的 Response 类,然后从中派生出特定的响应格式.

For anything else you're going to need some form of proprietary protocol and transport mechanism. Typically I write a simple socket protocol with a defined message structure (typically a message ID, CRC, message length and data payload). I then have some base message class that handles the comms and a set of derived messages for each specific command I want. For 2-way stuff that requires a response, I typically create a base Response class and then derive specific response formats from it.

这篇关于Windows Mobile (C#) - 在手机和 PC 之间进行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆