Java Reference
In-Depth Information
}
// doConnection
/**
* Here is a homemade login protocol. A password
* exchange could also be added.
**/
boolean login() {
fDataClient.println ("Waiting for login prompt...");
String msg
-
line = readNetInputLine ();
if (msg
-
line == null) return false;
fDataClient.println (msg
-
line);
if (!msg
-
line.startsWith ("Username:")) return false;
fDataClient.println ("Send username " +fUserName);
try {
writeNetOutputLine (fUserName);
}
catch (IOException e)
{
return false;
}
catch (Exception e)
{
fDataClient.println (
"
Error occurred in sending
username!
"
);
return false;
}
fDataClient.println ("Waiting for response...");
msg
-
line = readNetInputLine ();
if (msg
-
line == null) return false;
fDataClient.println (msg
-
line);
return true;
} // login
/** Do all of the steps needed to stop the
* connection. **/
public void finish () {
// Kill the thread and stop the server
fKeepRunning = false;
closeServer ();
}
// finish
/** Close the socket to the server. **/
void closeServer () {
if (fServer == null) return;
Search WWH ::
Custom Search