Here's the code.
public class testClient {
public static void main(String[] args) {
testClient abc = new testClient();
abc.go();
}
public void go() {
try {
Socket s = new Socket("127.0.0.1", 5000);
InputStreamReader sr = new InputStreamReader(s.getInputStream());
BufferedReader reader = new BufferedReader(sr);
String x = reader.readLine();
System.out.println(x);
reader.close();
} catch(IOException ex) {
ex.printStackTrace();
}
}
}
public class testServer {
public static void main(String[] args) {
testServer server = new testServer();
server.go();
}
public void go() {
try {
ServerSocket s = new ServerSocket(5000);
while(true) {
Socket sock = s.accept();
PrintWriter writer = new PrintWriter(sock.getOutputStream());
String toReturn = "No cake for you.";
writer.println(toReturn);
}
} catch(IOException ex) {
ex.printStackTrace();
}
}
}
java.io.*
and java.net.*
are imported in both classes.
Now, when I try to run these(using different terminals), nothing happens. What am I doing wrong?