我正在尝试通过Java套接字在C#中向我的客户端发送一个千兆字节的字节数组,但是我的数据中约有580k条目丢失了。我将数组中的每个条目都设置为10,但在某些时候它们变为0。
我的Java代码:
OutputStream outputStream = objSocket.getOutputStream();
byte[] dataBytesLength = new byte[4];
int toSendLen = dataBytes.length;
dataBytesLength[0] = (byte)(toSendLen & 0xff);
dataBytesLength[1] = (byte)((toSendLen >> 8) & 0xff);
dataBytesLength[2] = (byte)((toSendLen >> 16) & 0xff);
dataBytesLength[3] = (byte)((toSendLen >> 24) & 0xff);
outputStream.write(dataBytesLength);
outputStream.write(dataBytes);
我的C#代码:
byte[] receivedLengthBytes = new byte[4];
Socket.Receive(receivedLengthBytes);
int receivedLength = BitConverter.ToInt32(receivedLengthBytes, 0);
byte[] receivedBytes = new byte[receivedLength];
Socket.Receive(receivedBytes);
如果我循环遍历接收到的字节数组,则589824之后的所有内容都为0。我不确定为什么会发生这种数据丢失,不幸的是,将其拆分成许多500k块是不可行的。