-2
Q
通過UDP
A
回答
1
將數組轉換爲字節數組,然後發送字節數組。接收器將字節數組轉換回int [];您可以使用類DataOutputStream
創建字節數組。
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
int len = 0;
in protokollVersion = 1;
// Write a version, in case you want to change your format later, such that
// the receiver has a chance to detect which format version is used.
dos.writeInt(protokollVersion);
if (arr != null) {
len = arr.length;
}
dos.writeInt(arr.length);
for (int i = 0; i < len; i++) {
dos.writeInt(arr[i]);
}
dos.close();
byte[] bytes = bos.getBytes();
在接收器側,讀取使用DataInputStream(byte[] bytes)
和DataInputStream.readInt()
字節數組。
相關問題
- 1. 丟幀通過UDP
- 2. Streaming .ts通過UDP文件
- 3. 通過UDP接收響應
- 4. UDP連接不通過lan
- 5. C#.wav文件通過UDP
- 6. 通過Java發送UDP數據包
- 7. 通過udp發送的圖像損壞
- 8. LCM UDP報文通過共享網絡
- 9. 通過互聯網的UDP組播?
- 10. 通過Powershell獲取UDP連接列表
- 11. 通過UDP接收實時GPS數據
- 12. 通過UDP傳遞結構弱類型
- 13. 通過UDP發送的Ints是字節
- 14. Spring集成MQTT通過UDP或MQTT-SN
- 15. 通過UDP與QT發送文件
- 16. SOAP請求通過UDP的組播
- 17. 通過UDP發送數據包
- 18. 通過udp發送數據包
- 19. 通過UDP發送HEX值套接字
- 20. 通過udp流媒體h264/aacplus媒體
- 21. Matlab/simulink udp通道
- 22. Android的UDP通信
- 23. PHP套接字UDP通信
- 24. ACE和異步UDP通信
- 25. Android:通過UDP從線程發送加速度計數據
- 26. 通過互聯網將UDP廣播到外部網絡
- 27. 通過環回接口調度UDP數據包的延遲?
- 28. 通過GCDAsyncUdpSocket發送組播UDP失敗,Wireshark的
- 29. 使用cocoaasyncsocket通過UDP傳輸字符串
你能告訴我如何轉換它嗎?因爲我沒有從谷歌搜索找到很多幫助。 –
已更新的答案。 – AlexWien