当我从JAVA套接字向C#套接字发送一个大字节时,出现错误信息
" java.net.SocketException:通过peer重置连接:socket write 错误"
已被提示。
当字节很小时(例如," Hello world。"),它可以正常工作。
如何从JAVA套接字向C#套接字发送大字节? 另外,如何在JAVA代码中将JAVA字节转换为C#字节?
感谢。
以下是我的源代码:
JAVA代码:
byte[] decryptedAttachmentByte = IOUtils.toByteArray(decryptedAttachment);
OutputStream os = m_socket.getOutputStream();
int toSendLen = toSendBytes.length;
byte[] toSendLenBytes = new byte[4];
toSendLenBytes[0] = (byte)(toSendLen & 0xff);
toSendLenBytes[1] = (byte)((toSendLen >> 8) & 0xff);
toSendLenBytes[2] = (byte)((toSendLen >> 16) & 0xff);
toSendLenBytes[3] = (byte)((toSendLen >> 24) & 0xff);
os.write(toSendLenBytes);
os.write(toSendBytes); << Exception here
C#代码
byte[] rcvLenBytes = new byte[4];
clientSocket.Receive(rcvLenBytes);
int rcvLen = System.BitConverter.ToInt32(rcvLenBytes, 0);
byte[] rcvBytes = new byte[rcvLen];
clientSocket.Receive(rcvBytes);