S.V.P expliquez moi ce code

amine1988

عضو مميز
إنضم
22 جوان 2007
المشاركات
992
مستوى التفاعل
515
:besmellah1:
Bonjour,
j'ai télécharger un programme du net mon but est de trouvé un code qui permet de faire testes sur des ports d'une machine distante pour savoir s'il sont en écoute ou non en un temp meilleur
voila ce programme il marche très bien me je comprend pas la résultat
merci de me l'expliquer et de me le modifier afin qu'il rependrai a mes besoins
classe Ping
كود:
import java.io.*;
import java.net.*;
import java.nio.channels.*;
 
 
public class Ping {
 
private static int timeout; // Timeout in ms for pinging
private static Target t;
private static SocketChannel sc;
 
// Representation of a ping target
private static class Target {
 
public InetSocketAddress address;
public SocketChannel channel;
public long connectStart;
public long connectFinish = 0;
public Exception failure = null;
 
public Target(String host, int port) throws IOException 
{
address = new InetSocketAddress(InetAddress.getByName(host), port);
**
 
public long getPing() throws IOException, InterruptedException
{
if (connectFinish != 0)
    return connectFinish - connectStart;
else if (failure != null)
if (failure instanceof IOException) throw (IOException) failure;
else if (failure instanceof InterruptedException)throw (InterruptedException) failure;
else
return -2; //should not happen

el le main pour tester il faut juste modifier l'adresse ip

كود:
import java.io.IOException;
public class Main 
{
    public static void main(String[] args) throws InterruptedException, IOException
    {
    Ping p = null;
    System.out.println(p.ping("127.0.0.1", 3306, 4000)); //host,port, timeout in ms
    **
 
    
**

merci bonne soirée
:tunis:
 
ya si amine c'est un exercice résolu avec un logiciel de programmation il s'appelle JAVA pour que vous comprendre ce code il faut que tu comprend le JAVA d'abord?
 
c'est une simple application avec le java compilé avec l'eclipse elle permet la connexion reseaux (mnipulation des socket ) ...en bref programmation reseaux
 
C'est un code développé avec java; mais il est incomplet il manque la déclaration d'un constructeur ping avec 3 paramètres.
Ce code permet le test d'une connexion à une autre machine (@IP) à travers un port,
 
أعلى