Sockets

niketou Messages postés 295 Date d'inscription dimanche 4 mai 2003 Statut Membre Dernière intervention 6 décembre 2010 - 11 juin 2005 à 11:58
cs_neodante Messages postés 2835 Date d'inscription lundi 11 août 2003 Statut Modérateur Dernière intervention 16 décembre 2006 - 12 juin 2005 à 22:55
Salut je viens de telecharger c'ette source,je compile avec vj++ ca marche en local mais pas en resau pourquoi svp?.

import java.io.*; // for input output
import java.lang.*; // for Threads
import java.net.*; // sockets


/**
* @version 1.8
* @author Julien GARINO
*/


public class clientChat {


public static void main(String args[]) throws IOException {


/*******Declarations**********/
// Ports and Hosts
int port = 3000; // port
String myHost = "180.15.14.x";//"localhost"; // just change it with args[0] and will work through the network


// Sockets
Socket clientSocket = null; // Socket with PDA Client


// Inout/Output for PDA Client
BufferedReader isClient = null; // BufferedReader from PDA Client
PrintWriter osClient = null; // OutputStream to PDA Client
BufferedReader readfromline = null;


// Strings
String myString = null;
String sString = null;
int i = 0; // Translation counter
int Clientconnected = 0; // Connection marker
/********End declarations*********/


try {
System.out.print("\nClient.");
clientSocket = new Socket(myHost, port);
System.out.print("..started.\n\n");
}
catch (IOException e) {
System.out.print("..failed.\nProblem in the creation of the Socket : " +
e);
System.exit(1);
} //catch


try {
osClient = new PrintWriter(clientSocket.getOutputStream()); // prepare an OutputStream for the Client
isClient = new BufferedReader(new InputStreamReader(clientSocket.
getInputStream())); // InputStream from client
readfromline = new BufferedReader(new InputStreamReader(System.in));
}
catch (IOException e) {
System.out.println("Can't deal with the streams... : " + e);
} //catch


try {
while (true) {
myString = readfromline.readLine();
if (myString.trim().equals("/bye")) {
osClient.println("/bye");
osClient.flush();
clientSocket.close();
System.exit(1);
}


osClient.println(myString); // Write it
osClient.flush(); // put it onto the network
System.out.println("\nSending...: '" + myString + "' ...done.");
myString = isClient.readLine();
System.out.println("From server :-[===> " + myString + "\n");
} //while
} //try
catch (Exception e) {
System.out.println("Exception while sending data" + e);
System.exit(1);
} // catch
System.out.println("Closing connection to client");
// System.exit(0);
} // void main
} // clientChat class

1 réponse

cs_neodante Messages postés 2835 Date d'inscription lundi 11 août 2003 Statut Modérateur Dernière intervention 16 décembre 2006 11
12 juin 2005 à 22:55
Salut,

euh oublie VJ++ (VS 6.0 non ??) voilà la réponse à ta question ... hihi c simple non ???

Esst-ce que tu as essayé avec javac ???



++
0
Rejoignez-nous