c# - data format in connection betwen desktop app and UWP application
问题描述
im creating a client-server service betwen desktop App (c#) and HoloLens (UWP). The server runs on HoloLens, while PC App is the client.
I meet some problems with transfering data and here is my question to you.
While UWP server uses a Windows.Netowrking and Windows.Networking.Sockets, it seems to receive and send data as strings. PC App uses System.Net and System.Net.Sockets and before sending the string it requires converting string into byte format.
Can this be an issue? I could not find to much documentation for Windows.Networking and i dont know if the data before sending is converted to byte anyway.
解决方案
我不知道发送前的数据是否无论如何都转换为字节
当您使用网络 API 调用 Write() 或 Send() 时,您通常可以选择提供多种数据类型,无论是字符串、字节 [] 还是 int - 但这不会影响数据的物理方式传送。
在内部,传输将以有效的方式“序列化”(作为二进制流),但您不需要关心这些细节。
因为另一端将能够将该数据处理为 byte[]、int[] 或字符串。
您可能想要研究的一个常见问题是字节序,或者检查您如何将字符串更改为字节 []。即你在字符串之间改变的问题,或者不同的字节[]等不正确的问题。您可以阅读System.Text.Encoding以检查您是否在 byte[] 和 string 之间正确移动。
//Turn a string into a byte[], for your PC app to send
byte[] byteData = System.Text.Encoding.ASCII.GetBytes("Message");
//On the other end read that byte[] into ASCII characters
char[] charsData = System.Text.Encoding.ASCII.GetChars(byteData);
//Check you read something, and turn those chars into a string.
if (charsData != null && charsData.Length > 0)
string stringData = new string(chars);
推荐阅读
- artificial-intelligence - Tensor flow lite 中的错误对象检测
- java - 模拟 databaseMetaData.getTables() 方法时 ResultSet 为空
- python - python 显示此类型错误:字符串索引必须是整数
- javascript - js如何选择href中的部分选择器来制作上一个和下一个按钮?
- java - 如何分配给方法不同类的参数?
- asp.net-core - EF Core 从 Google Cloud Run 连接到 Google Cloud SQL
- python - 如何在没有导入的情况下在 Python 中转置数组?
- azure-cosmosdb - Cosmos DB 设置索引精度
- c# - 使用 Azure 函数链接模式时,Activity 之间的延迟时间增加
- javascript - 如何在 Flask 中突出显示文本