Playing with a few tutorials on sockets but struggling to connect.
My tomcat server is at eric.server.com
and is running a ajp connector on port 8052.
I want to use the knock knock java tutorial to connect. I've uploaded the KnockKnockProtocol.class and KnockKnockServer.class to eric.server.com/apps/knock
On the tutorial it shows this:
kkSocket = new Socket("tarranis", 4444);
Which I have changed to:
kkSocket = new Socket("eric.server.com/apps/knock", 8052);
I then run the client program from eclipse but I just get the UnknownHostException.
Could someone please explain what I'm doing wrong, totally new to Tomcat and servlets in general?
TIA
import java.io.; import java.net.;
public class KnockKnockClient { public static void main(String[] args) throws IOException {
Socket kkSocket = null;
PrintWriter out = null;
BufferedReader in = null;
try {
kkSocket = new Socket("eric.server.com", 8052);
out = new PrintWriter(kkSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(kkSocket.getInputStream()));
} catch (UnknownHostException e) {
System.err.println("Don't know about host.");
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get I/O for the connection to.");
System.exit(1);
}
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
String fromServer;
String fromUser;
while ((fromServer = in.readLine()) != null) {
System.out.println("Server: " + fromServer);
if (fromServer.equals("Bye."))
break;
fromUser = stdIn.readLine();
if (fromUser != null) {
System.out.println("Client: " + fromUser);
out.println(fromUser);
}
}
out.close();
in.close();
stdIn.close();
kkSocket.close();
}
}