IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Entrée/Sortie Java Discussion :

arrêter connexion TCP sous UNIX


Sujet :

Entrée/Sortie Java

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    71
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 71
    Points : 50
    Points
    50
    Par défaut arrêter connexion TCP sous UNIX
    Bonjour,

    J'ai développé un serveur TCP qui me permet de faire une interface entre deux applications. Cette class s'exécutera sous UNIX en tâche de fond.
    Comment faire pour l'arrêter?
    Merci de vos réponses.

  2. #2
    Membre actif
    Homme Profil pro
    Architecte de système d'information
    Inscrit en
    Mars 2002
    Messages
    192
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Architecte de système d'information

    Informations forums :
    Inscription : Mars 2002
    Messages : 192
    Points : 252
    Points
    252
    Par défaut
    CTRL-C, kill -9, shutdown -f, débrancher la prise, un coup de masse dans le serveur, ...

    Y a plein de solutions, certainement même des plus propres.

    Sans rire c'est quoi ton besoin/ta question exactement?

    Tu veux arréter ton processus, mais de quelle manière?
    • sur un appel d'API
    • sur une trame TCP
    • ...

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    71
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 71
    Points : 50
    Points
    50
    Par défaut
    CTR-C ????
    Je peux aussi basculer l'alimentation des 80 serveurs sur OFF.

    Bref, j'aimerais pouvoir libèrer proprement le port d'écoute de mon serveur par une trame TCP par exemple ou mieux par un appel de commande UNIX mais un peu moins sauvage que le kill.

  4. #4
    Membre actif
    Homme Profil pro
    Architecte de système d'information
    Inscrit en
    Mars 2002
    Messages
    192
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Architecte de système d'information

    Informations forums :
    Inscription : Mars 2002
    Messages : 192
    Points : 252
    Points
    252
    Par défaut
    C'était bien pour ça que je provoquais un peu, pour avoir plus d'infos.

    Quelque chose de propre, joli, maintenable, accessible, "monitorable", ultra simple qui tient en trois lignes ... c'est de faire une façade JMX.
    Publie juste un service du style ServerHandlerMBean avec une méthode stop.
    Ce sera appellable de plein de manière différente, y compris par une console d'administration distante HTTP (ex: JManage) ou par une console JMX standard (jconsole dans le jdk).

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    71
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 71
    Points : 50
    Points
    50
    Par défaut
    Merci pour ton aide.
    Je n'ai pas une grande expérience de développement en java et je n'ai pas tout compris dans ta réponse.
    Je pensais qu'il y avait simplement une commande unix qui me permettrait de libèrer le port d'écoute.
    je m'en suis finalement sortie avec un client qui envoie une trame d'arrêt.

  6. #6
    Membre actif
    Homme Profil pro
    Architecte de système d'information
    Inscrit en
    Mars 2002
    Messages
    192
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Architecte de système d'information

    Informations forums :
    Inscription : Mars 2002
    Messages : 192
    Points : 252
    Points
    252
    Par défaut
    Bonjour,

    J'ai réalisé un petit programme d'exemple qui explique comment celà fonctionne.
    C'est relativement simple tu verras.

    En attendant, j'ai un problème de FTP pr déposer le fichier, si tu veux que je t'envoie le projet d'exemple, envoie moi un MP avec ton email.

    Je posterai ici, le projet et une doc dès que j'aurai récupéré mon accès FTP.

  7. #7
    Membre actif
    Homme Profil pro
    Architecte de système d'information
    Inscrit en
    Mars 2002
    Messages
    192
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Architecte de système d'information

    Informations forums :
    Inscription : Mars 2002
    Messages : 192
    Points : 252
    Points
    252
    Par défaut
    Ca y est j'ai récupéré ma connexion FTP, je peux mettre à disposition l'example, qui est ici (les sources sont le jar).

    Le projet d'exemple contient :
    • une classe RunningServer qui est en fait une thread qui tourne en affichant le temps système. Rien de bien méchant de ce coté là, c'était juste pour simuler un traitement.
    • une classe & une interface pour la gestion du serveur (ici je n'ai fait que l'arrêt). C'est cette classe ServerManager et cette interface ServerManagerMBean qui nous interresse. L'interface décrit la méthode qui sera publiée au travers de JMX. La classe implémente cette interface.
    • une classe qui initialise le programme MainApp. Outre la création des serveurs, ce qui est important c'est l'enregistrement de la classe ServerManager en tant que "managed bean".


    Le lancement du programme s'effectue avec la commande suivante:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    java -Dcom.sun.management.jmxremote -jar jmx-example.jar
    L'option -Dcom.sun.management.jmxremote est obligatoire pour pouvoir connecter une cosole JMX en local, voir ici.

    Ensuite, pour arréter le serveur, il suffit de lancer par exemple la console JMX du jdk sun: jconsole (ouvrir une fenêtre CMD, taper jconsole, JAVA_HOME/bin doit être dans ton path).

    La fenêtre suivante s'ouvre :


    Appuyer sur connect. Dès lors tu est connecté à l'application RMI qui gère les beans publiés dans la JVM. Entre autre, on trouve le notre sous l'entrée "fr.brouillard.server.manager". Il ne reste plus qu'à aller appeler la méthode STOP publiée par notre bean, accessible depuis l'onglet Operations de notre MBean.


    Notre serveur s'arrète...

    Voici une log d'exécution du programme d'exemple.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    Start of the application, creation of required objects
    RunningServer[0] created
    RunningServer[1] created
    RunningServer[2] created
    RunningServer[3] created
    RunningServer[4] created
    ServerManager created
    Trying to register the ServerManager
    ServerManager registered under fr.brouillard.server.manager:type=ServerManager
    Launching RunningServer[0]
    Launching RunningServer[1]
    Launching RunningServer[2]
    [0] Server is running: 1216394364719
    [1] Server is running: 1216394364719
    Launching RunningServer[3]
    [2] Server is running: 1216394364719
    Launching RunningServer[4]
    [3] Server is running: 1216394364719
    [4] Server is running: 1216394364719
    [4] Server is running: 1216394365219
    [1] Server is running: 1216394365719
    [4] Server is running: 1216394365719
    [0] Server is running: 1216394366219
    [4] Server is running: 1216394366219
    [1] Server is running: 1216394366719
    [3] Server is running: 1216394366719
    [4] Server is running: 1216394366719
    [2] Server is running: 1216394366719
    [4] Server is running: 1216394367219
    [1] Server is running: 1216394367719
    [0] Server is running: 1216394367719
    [4] Server is running: 1216394367719
    [4] Server is running: 1216394368220
    [1] Server is running: 1216394368720
    [3] Server is running: 1216394368720
    [4] Server is running: 1216394368720
    [2] Server is running: 1216394368720
    [0] Server is running: 1216394369220
    [4] Server is running: 1216394369220
    [1] Server is running: 1216394369720
    [4] Server is running: 1216394369720
    [4] Server is running: 1216394370220
    Asking RunningServer[0]to stop
    [0] Running server is asked to stop
    We now wait for the real stop of RunningServer[0]
    RunningServer[0] is now stopped
    [1] Server is running: 1216394370720
    Asking RunningServer[1]to stop
    [1] Running server is asked to stop
    We now wait for the real stop of RunningServer[1]
    [2] Server is running: 1216394370720
    [3] Server is running: 1216394370720
    [4] Server is running: 1216394370720
    [4] Server is running: 1216394371220
    RunningServer[1] is now stopped
    Asking RunningServer[2]to stop
    [2] Running server is asked to stop
    We now wait for the real stop of RunningServer[2]
    [4] Server is running: 1216394371720
    [4] Server is running: 1216394372221
    [3] Server is running: 1216394372721
    RunningServer[2] is now stopped
    [4] Server is running: 1216394372721
    Asking RunningServer[3]to stop
    [3] Running server is asked to stop
    We now wait for the real stop of RunningServer[3]
    [4] Server is running: 1216394373221
    [4] Server is running: 1216394373721
    [4] Server is running: 1216394374221
    [4] Server is running: 1216394374721
    RunningServer[3] is now stopped
    Asking RunningServer[4]to stop
    [4] Running server is asked to stop
    We now wait for the real stop of RunningServer[4]
    RunningServer[4] is now stopped
    The servers are stopped, no other threads are running, the JVM will stop
    Jette un coup d'oeil au code, c'est relativement simple. J'espère que ça t'aideras et que ça en aidera d'autres.
    Si tu veux d'autres explications n'hésites pas.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Connexion TCP/IP sous Excel
    Par jazzybluesy dans le forum Macros et VBA Excel
    Réponses: 0
    Dernier message: 28/01/2013, 20h50
  2. Connexion mysql sous unix
    Par Tonii dans le forum Administration
    Réponses: 1
    Dernier message: 07/08/2012, 14h38
  3. [AC-2003] Connexion TCP sous en VBA sous access
    Par lololebricoleur dans le forum Access
    Réponses: 3
    Dernier message: 12/03/2012, 19h21
  4. Problème de connexion au serveur sous unix..
    Par da3_insa dans le forum Débuter avec Java
    Réponses: 3
    Dernier message: 26/10/2008, 12h53
  5. client/serveur tcp/ip en c sous unix
    Par oclone dans le forum Développement
    Réponses: 8
    Dernier message: 19/04/2005, 18h55

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo