T
Thomas OZENNE
Hello,
I'm trying to connect to a socket and read from it just the code loop on
read() can someone help? what can I do ?
The code :
import java.io.*;
import java.net.*;
public class NewsTest {
public static void main(String[] args) throws IOException {
Socket echoSocket = null;
PrintWriter out = null;
InputStreamReader in = null;
try {
echoSocket = new Socket("smtp.free.fr", 25);
out = new PrintWriter(echoSocket.getOutputStream(), true);
in = new InputStreamReader(echoSocket.getInputStream());
} catch (UnknownHostException e) {
System.err.println("Don't know about host: taranis.");
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get I/O for "
+ "the connection to: taranis.");
System.exit(1);
}
BufferedReader stdIn = new BufferedReader(
new InputStreamReader(System.in));
String userInput= new String();
String output = new String();
int c =0;
while (userInput!="end") {
while((c = in.read())>= 0)
{
System.out.print((char)c);
}
userInput = stdIn.readLine();
out.println(userInput);
System.out.println(userInput);
}
System.out.println("end");
out.close();
in.close();
stdIn.close();
echoSocket.close();
}
}
I'm trying to connect to a socket and read from it just the code loop on
read() can someone help? what can I do ?
The code :
import java.io.*;
import java.net.*;
public class NewsTest {
public static void main(String[] args) throws IOException {
Socket echoSocket = null;
PrintWriter out = null;
InputStreamReader in = null;
try {
echoSocket = new Socket("smtp.free.fr", 25);
out = new PrintWriter(echoSocket.getOutputStream(), true);
in = new InputStreamReader(echoSocket.getInputStream());
} catch (UnknownHostException e) {
System.err.println("Don't know about host: taranis.");
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get I/O for "
+ "the connection to: taranis.");
System.exit(1);
}
BufferedReader stdIn = new BufferedReader(
new InputStreamReader(System.in));
String userInput= new String();
String output = new String();
int c =0;
while (userInput!="end") {
while((c = in.read())>= 0)
{
System.out.print((char)c);
}
userInput = stdIn.readLine();
out.println(userInput);
System.out.println(userInput);
}
System.out.println("end");
out.close();
in.close();
stdIn.close();
echoSocket.close();
}
}