-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. 通過UDP
- 3. 丟幀通過UDP
- 4. 通過UDP重複通訊
- 5. C#.wav文件通過UDP
- 6. UDP連接不通過lan
- 7. 分散負載通過UDP
- 8. 通過UDP發送圖片
- 9. 通過UDP發送音頻
- 10. Streaming .ts通過UDP文件
- 11. 通過UDP接收響應
- 12. 如何通過UDP通告TCP主機?
- 13. 通過udp從simulink塊接收數據
- 14. 通過UDP套接字發送數據
- 15. LCM UDP報文通過共享網絡
- 16. PYTHON循環通過dict_keys和UDP發送
- 17. SOAP請求通過UDP的組播
- 18. Android通過udp發送mpegts流
- 19. 通過UDP多播發送很長
- 20. 通過udp發送的圖像損壞
- 21. 通過Powershell獲取UDP連接列表
- 22. 通過互聯網的UDP組播?
- 23. 最大/ MSP通過UDP報文格式
- 24. 通過UDP傳遞結構弱類型
- 25. 通過Java發送UDP數據包
- 26. 通過UDP發送HEX值套接字
- 27. 在Java中通過udp發送對象
- 28. 有時不通過UDP連接
- 29. UDP打洞不打算通過對3G
- 30. 通過UDP發送的Ints是字節
你能告訴我如何轉換它嗎?因爲我沒有從谷歌搜索找到很多幫助。 –
已更新的答案。 – AlexWien