nikos,
I might be the least qualified to answer this, but I'm right about having almost exactly the same problem as yours, thanx to your mentioning of Sun's Java Tutorial, I somehow managed to solve my problem.
I figure that you are trying to make the server says something to the client, and the client host's user key-in something and throws back to server. If that's the case, you code could be modified as below:
-------------------------------
MyServer
-------------------------------
import java.io.*;
import java.net.*;
public class MyServer {
public static void main(String[] args) throws Exception {
ServerSocket server=null;
server=new ServerSocket(4664);
Socket client=null;
client=server.accept();
PrintWriter pw=new PrintWriter(client.getOutputStream(),true);
BufferedReader br=new BufferedReader(new InputStreamReader(client.getInputStream()));
pw.println("nikos server");
System.out.println(br.readLine());
pw.println("tralala");
System.out.println(br.readLine());
pw.println("ade allo ena test");
System.out.println(br.readLine());
pw.println("ade allo ena");
System.out.println(br.readLine());
pw.close();
br.close();
client.close();
server.close();
}
}
-------------------------------
MyClient
-------------------------------
import java.io.*;
import java.net.*;
public class MyClient {
public static void main(String[] args) throws Exception {
Socket cs=null;
PrintWriter out=null;
BufferedReader br=null;
InetAddress ad=InetAddress.getLocalHost();
cs=new Socket("192.168.0.3",4664);
out=new PrintWriter(cs.getOutputStream(),true);
br=new BufferedReader(new InputStreamReader(cs.getInputStream()));
BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
String sn;
while((sn=br.readLine())!=null){
System.out.println(sn); //<-The server says what?
sn=stdin.readLine(); //<-The client user replies.
out.println("echo: " + sn); //<-The client host sends user input to server
}
out.println("niooo");
out.close();
br.close();
stdin.close();
cs.close();
}
}
It ain't pretty, but functional.
I haven't figure out what the KnockKnockProtocal means in Sun's Tutorial.