Linux から Windows にデータを取得するには、C++ で次の Java 機能を複製する必要があります。Winsock2 が最善の方法ですか?.
また、提案する参照コードはありますか?
ティア、B
java.nio.ByteBuffer をインポートします。
パブリック クラス MessageXdr {
プライベート ByteBuffer バッファ;
プライベート int サイズ。
// taille max corps de message
private static final int T_MAX_CORPS_MSG = 16384;
public MessageXdr() {
バッファ = ByteBuffer.allocate(4 * T_MAX_CORPS_MSG);
サイズ = 0;
}
public MessageXdr(byte[] 配列)
{
ByteBuffer tmpBuffer = ByteBuffer.wrap(配列);
バッファ = tmpBuffer.asReadOnlyBuffer();
サイズ = 配列.長さ;
}
public int getSize()
{
サイズを返します。
}
public int getPosition()
{
戻り値 buffer.position();
}
パブリックバイト[] getArray()
{
buffer.array(); を返します。
}
public void resetBuffer()
{
サイズ = 0;
buffer.rewind();
}
public int readInt()
{
int retour = buffer.getInt();
リターンリターン;
}
public long readUnsignedInt()
{
ByteBuffer tmp = ByteBuffer.allocate(8);
tmp.putInt(0);
tmp.putInt(buffer.getInt());
tmp.getLong(0) を返します。
}
public float readFloat()
{
float retour = buffer.getFloat();
リターンリターン;
}
public void writeInt(int v)
{
buffer.putInt(v);
サイズ+=4;
}
public void writeFloat(float v)
{
buffer.putFloat(v);
サイズ+=4;
}
}