Probleme dans la creation d'un ServerSocket en java
Bonsoir,
Je veux créer un proxy en java, pour cela j'ai besoin du package java.net.socket
Mais lors de l'execution de mon code, ca bloque sur ServerSocket server=new ServerSocket(port)
VOici le code :
Code:
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
|
import java.net.*;
import java.io.*;
import java.util.*;
public class Serveur {
private Vector _tabClient=new Vector();
private int _nbClient=0;
public static String[] IP;//pour filtrer les ip qui se connecte
public static void main(String[] args) {
Serveur server=new Serveur();
try{
IP=new String[2];
IP[0]="/127.0.0.1";IP[1]="/195.68.1.11";
Integer port;
if(args.length<=0){
port=new Integer("22000"); // si pas d'argument : port 18000 par défaut
}
else {
port = new Integer(args[0]); // sinon il s'agit du numéro de port passé en argument
}
//on creer la connexion
ServerSocket theConnexion=new ServerSocket(port.intValue());
System.out.println("---------Serveur lancer avec succes-------------");
//boucle d attente de client
while(true){
/*--------------A chaque nouveau client on ouvre un thread proxy-------------------------------*/
new Proxy(server,theConnexion.accept(),IP);
}
}
catch(Exception e){
}
}
synchronized public int addClient(PrintWriter out)
{
_nbClient++; // un client en plus ! ouaaaih
_tabClient.addElement(out); // on ajoute le nouveau flux de sortie au tableau
return _tabClient.size()-1; // on retourne le numéro du client ajouté (size-1)
}
synchronized public void delClient(int i)
{
_nbClient--; // un client en moins ! snif
if (_tabClient.elementAt(i) != null) // l'élément existe ...
{
_tabClient.removeElementAt(i); // ... on le supprime
}
}
} |
Pourquoi? Est ce quelqu'un peut m'aider?
Bonne soirée
Krikri