我必须在 C++ 中复制以下 Java 功能才能将数据从 Linux 获取到 Windows。Winsock2 是最好的方法吗?
另外,有什么参考代码可以建议吗?
TIA,乙
导入 java.nio.ByteBuffer;
公共类 MessageXdr {
私有 ByteBuffer 缓冲区;
私有 int 大小;
// taille max corps de message
私有静态最终 int T_MAX_CORPS_MSG = 16384;
公共 MessageXdr() {
缓冲区 = ByteBuffer.allocate(4 * T_MAX_CORPS_MSG);
大小=0;
}
公共 MessageXdr(byte[] 数组)
{
ByteBuffer tmpBuffer = ByteBuffer.wrap(array);
缓冲区 = tmpBuffer.asReadOnlyBuffer();
大小 = 数组长度;
}
公共 int getSize()
{
返回大小;
}
公共 int getPosition()
{
返回缓冲区。位置();
}
公共字节[] getArray()
{
返回缓冲区.array();
}
公共无效resetBuffer()
{
大小 = 0;
缓冲区.rewind();
}
公共 int readInt()
{
int retour = buffer.getInt();
回程;
}
public long readUnsignedInt()
{
ByteBuffer tmp = ByteBuffer.allocate(8);
tmp.putInt(0);
tmp.putInt(buffer.getInt());
返回 tmp.getLong(0);
}
公共浮动读取浮动()
{
float retour = buffer.getFloat();
回程;
}
公共无效writeInt(int v)
{
缓冲区.putInt(v);
尺寸+=4;
}
公共无效writeFloat(浮动v)
{
缓冲区.putFloat(v);
尺寸+=4;
}
}