[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Socket



Hello everybody,
 
I'm trying to run an example with Socket (with only 1 machine), but I don't succeed.
Can someone help me please by telling me which labraries that I need.
This is the code that I have for the moment:
 
----------------- Client 
// Try to connect to server and port
// client thread waits here
// until server accepts
Socket s = new Socket( "localhost", 8888 );
// get streams to allow us to read
// and write to client
BufferedReader in = new BufferedReader(
   new InputStreamReader( s.getInputStream() )
   );
PrintStream out = new PrintStream( s.getOutputStream() );
// read and write to server
out.println( “Hello” );
out.flush();
String t = in.readLine();
System.out.println( t );
----------------- Server
 
// create ServerSocket, specify port
ServerSocket ss = new ServerSocket( 8888 );
// server thread waits here for client
Socket s = ss.accept();
// get streams to allow us to read
// and write to client
BufferedReader in = new BufferedReader(
   new InputStreamReader( s.getInputStream() )
   );
PrintStream out = new PrintStream( s.getOutputStream() );
// read and write to client
String t = in.readLine();
System.out.println( t );
out.println( “Hi” );
out.flush();
 
If someone else have an other example which can help me, he can give me it.I will be recognizing.
 
Bye


Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger
Téléchargez le ici !