Java方法在Eclipse和编译的jar中运行,但不在NetBeans中运行

时间:2014-04-23 00:29:54

标签: java eclipse netbeans

我有一种方法可以向游戏服务器发送请求并从服务器接收播放器数据。

当我在Eclipse中运行此代码时,它正常工作,服务器发送正确的数据。它也可以从独立的jar中正常工作。

如果我在Netbeans中运行相同的代码,远程服务器基本上拒绝该请求并发送“disconnect”

this.address = InetAddress.getByName(address);
this.connection = new DatagramSocket();

public byte[] sendStatus() throws IOException{
    //Construct the buffer from the command, then the PREFIX
    byte[] addOn = "rcon \"Password\" status".getBytes();
    byte[] toSend = new byte[addOn.length + PACKET_PREFIX.length];

    //Combine into one bytes array
    System.arraycopy(PACKET_PREFIX, 0, toSend, 0, PACKET_PREFIX.length);
    System.arraycopy(addOn, 0, toSend,PACKET_PREFIX.length, addOn.length);

    System.out.println(new String(toSend));
    //Make the toSend packet
    DatagramPacket packet = new DatagramPacket(toSend, toSend.length, this.address, 28960);

    //Now we send it
    this.connection.send(packet);

    //And receive the data.
    byte[] buffer = new byte[65536];
    DatagramPacket rec = new DatagramPacket(buffer, buffer.length);

    this.connection.receive(rec);

    byte[] data = rec.getData();

    return data;
}

感谢任何帮助。上面两行在别处定义。

0 个答案:

没有答案