What seems like a basic socket connection question:
The program first initiates the Socket Connection, to which the server should reply:
"$lock [some random String]
$servername [name of the server]"
To which I have to reply:
"$key [some String found by $lock]
$username [client username]"
Now when I execute this program, I only receive the $lock and not the $servername.
Now the problem might be that i use...
String inLine = input.readLine();
Does the readLine() only read one line?
It seems as if the program is attempting to get more info from the server because it hangs until the server drops the connection.
How do I read everything that the server is trying to send to me?
Source:
public static void EstablishConnection (String[] args) {
System.out.println("-- Program Started!");
Socket server = null;
BufferedReader input = null;
PrintWriter output = null;
String serverIP = "192.168.1.104";
String key = null;
int portNum = 1090;
try {
server = new Socket(serverIP, portNum);
output = new PrintWriter(server.getOutputStream(), true);
input = new BufferedReader(new InputStreamReader(server.getInputStream()));
} catch (UnknownHostException e) {
e.printStackTrace();
System.exit(100);
} catch (IOException e) {
e.printStackTrace();
System.exit(101);
}
try {
String inLine = input.readLine();
key = breakLock(inLine.substring(inLine.indexOf(' ') + 1, inLine.length()));
System.out.println("<< " + inLine);
} catch (IOException e) {
e.printStackTrace();
System.exit(101);
}
String outLine = ("$key " + key + "\n$nick connectTo");
output.print(outLine);
System.out.println(">> " + outLine);
}
By the way, what's the syntax for the ljcut?