Questo pezzo di codice mi da errore di TimeOut; sembrerebbe non rispondere il server indicato sulla porta 43.
Sapreste aiutarmi?
Grazie.
Codice PHP:
import java.net.*;
import java.io.*;
class whois {
public static void main(String args[]) throws Exception {
try {
int c;
// apre 1 connessione a 1 porta “whois” sul server InterNIC
Socket s = new Socket("whois.nic.it", 43);
// ‘in’ è il canale di input associato alla socket s
InputStream in = s.getInputStream();
// ‘out’ è il canale di output associato alla socket s
OutputStream out = s.getOutputStream();
String str = (args.length == 0 ? "mcgraw-hill.com" : args[0]) + "\n";
// estrae l’array di byte
byte buf[] = str.getBytes();
// scrive l’array completo nel flusso di output
out.write(buf);
// read legge il prossimo byte di dati: restituisce -1 se è stata raggiunta la fine dello stream
while((c = in.read()) != -1) {
System.out.print((char) c);
}
// chiude la socket ed i canali di I/O ad esso associati
s.close();
} // chiusura try
catch (UnknownHostException ex) {
System.out.println(ex.getMessage()+" causa: "+ex.getCause());
} // chiusura catch
} //chiusura main
} // chiusura class whois

Rispondi quotando