Utilizzo di java per interrogare le informazioni del server counter-strike 1.6


Ragazzi Sto cercando di scrivere un semplice programma java per interrogare il server counter-strike 1.6:

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class Test {

    private static DatagramSocket ds;

    /**
     * @param args
     */
    public static void main(String[] args) {
        try {
            ds = new DatagramSocket(27024);
            byte[] data;
            // TSource Engine Query
            char peer0_0[] = { 
                0xff, 0xff, 0xff, 0xff, 
                0x54, 0x53, 0x6f, 0x75,
                0x72, 0x63, 0x65, 0x20, 
                0x45, 0x6e, 0x67, 0x69, 
                0x6e, 0x65, 0x20, 0x51, 
                0x75, 0x65, 0x72, 0x79, 0x00 
            };
            data = new String(peer0_0).getBytes();

            System.out.println("send:" + new String(data));

            DatagramPacket dp = new DatagramPacket(data, 0, data.length, InetAddress.getByName("219.133.59.20"), 27021);
            ds.send(dp);
            byte[] rec = new byte[1024];
            DatagramPacket dp2 = new DatagramPacket(rec, 1024);
            ds.receive(dp2);

            System.out.println("revice:" + new String(rec));

            ds.close();
        } catch (IOException e) {
            e.printStackTrace();
            if(ds != null) ds.close();
        }
    }

}

Dopo aver inviato la query msg, non ha ricevuto alcuna cosa e il programma non uscirà. Sono sicuro che c'è un server su 219.133.59.20:27021 cosa c'è che non va nel mio codice ?

Author: CaiNiaoCoder, 2011-09-08

1 answers

Ho eseguito il tuo codice senza problemi. L'output è il seguente:

send:ÿÿÿÿTSource Engine Query
revice:ÿÿÿÿm127.0.0.1:27021CoVerT战队深圳6å?·ç–¯å?‹è®°æœ?务器ã€?KP】

Sospetto che tu stia avendo problemi con il tuo firewall/router. Da http://download.oracle.com/javase/tutorial/networking/datagrams/index.html :

Nota: Molti firewall e router sono configurati per non consentire UDP pacchetto. Se hai problemi di connessione a un servizio al di fuori del tuo firewall, o se i client hanno problemi di connessione al servizio, chiedere l'amministratore di sistema se UDP è consentito.

 3
Author: Mansoor Siddiqui, 2011-09-08 04:43:20