*/
class wcKeepAlive extends Thread {
- wcCitServer serv; /* Pointer to server connection class */
+ wcCitServer serv; /* Pointer to server connection class */
boolean FullKeepAlives; /* TRUE for full keepalives, FALSE for half keepalives */
- wcKeepAlive() {
- }
-
- public void PointToServer(wcCitServer which_serv, boolean WhatKindOfKeepAlives) {
+ wcKeepAlive() {
+ } public void PointToServer(wcCitServer which_serv,
+ boolean WhatKindOfKeepAlives) {
serv = which_serv;
serv.AddClientThread(this);
FullKeepAlives = WhatKindOfKeepAlives;
- }
+ }
public void run() {
String buf;
- while(true) {
+ while (true) {
/* Sleep for sixty seconds between keepalives. */
try {
sleep(60000);
- }
- catch (InterruptedException e) {
- }
+ }
+ catch(InterruptedException e) {
+ }
/* Full keepalives - send a NOOP, wait for a reply, then retrieve
* express messages if the server said there are any.
*/
if (FullKeepAlives) {
buf = serv.ServTrans("NOOP") + " ";
- }
+ }
/* Half keepalives - blindly send a NOOP and we're done. */
else {
serv.ServPuts("NOOP");
- }
-
}
+
}
-
}
+}
+
/*
public void SetTransBuf(String bufstring) {
TransBuf = bufstring;
- }
-
- public String GetTransBuf() {
+ } public String GetTransBuf() {
return TransBuf;
- }
+ }
/* attach to the server */
- private void BuildConnection(String ServerHost, int ServerPort, boolean WhichKA) {
+ private void BuildConnection(String ServerHost, int ServerPort,
+ boolean WhichKA) {
String buf;
try {
sock = new Socket(ServerHost, ServerPort);
- ofp = new
- DataOutputStream(sock.getOutputStream());
- ifp = new
- DataInputStream(sock.getInputStream());
- }
+ ofp = new DataOutputStream(sock.getOutputStream());
+ ifp = new DataInputStream(sock.getInputStream());
+ }
catch(UnknownHostException e) {
System.out.println(e);
- }
+ }
catch(IOException e) {
System.out.println(e);
- }
+ }
/* Connection established. At this point, this function
* has the server connection all to itself, so we can do
* whatever we want with it. */
-
- /* Get the 'server ready' message */
+
+ /* Get the 'server ready' message */
buf = ServGets();
/* Identify the client software to the server */
ServTrans("IDEN 0|5|001|Cit/UX Java Client|");
-
+
/* Download various information about the server */
SetTransBuf("");
buf = ServTrans("INFO");
- StringTokenizer InfoST = new StringTokenizer(TransBuf,"\n");
+ StringTokenizer InfoST =
+ new StringTokenizer(TransBuf, "\n");
while (InfoST.hasMoreTokens()) {
ServerInfo.addElement(InfoST.nextToken());
- }
+ }
/* At this point, all server accesses must cooperate with
ka.PointToServer(this, WhichKA);
ka.start();
- }
+ }
/*
* Attach to server command for the primary socket
*/
public void AttachToServer(String ServerHost, int ServerPort) {
-
+
/* Connect to the server */
/* NOTE ... we've changed the primary connection keepalives to HALF because we're using the
* primary connection to jump right into a chat window.
*/
PrimaryServerHost = ServerHost;
PrimaryServerPort = ServerPort;
- }
+ }
/*
*/
public String GetServerHost() {
return PrimaryServerHost;
- }
+ }
- public int GetServerPort() {
+ public int GetServerPort() {
return PrimaryServerPort;
- }
+ }
/*
* Set up a piggyback connection
*/
- public void Piggyback(wcCitServer PrimaryServ, boolean KeepAliveType) {
+ public void Piggyback(wcCitServer PrimaryServ,
+ boolean KeepAliveType) {
PrimaryServerHost = PrimaryServ.GetServerHost();
PrimaryServerPort = PrimaryServ.GetServerPort();
PrimaryServerUser = PrimaryServ.GetUserName();
PrimaryServerPassword = PrimaryServ.GetPassword();
BuildConnection(PrimaryServerHost, PrimaryServerPort,
KeepAliveType);
-
- }
+
+ }
public String ServInfo(int index) {
String retbuf;
if (index >= ServerInfo.size()) {
- return("");
- }
- else {
+ return ("");
+ } else {
retbuf = ServerInfo.elementAt(index).toString();
- return(retbuf);
- }
+ return (retbuf);
}
+ }
/* read a line from the server */
public String ServGets() {
-
+
String buf = "";
try {
buf = ifp.readLine();
- }
+ }
catch(IOException e) {
System.out.println(e);
- }
- return buf;
}
+ return buf;
+ }
/* write a line to the server */
try {
ofp.writeBytes(buf + "\n");
- }
+ }
catch(IOException e) {
System.out.println(e);
- }
}
+ }
/* lock the server connection so other threads don't screw us up */
public synchronized void BeginTrans() {
- while(in_trans) {
+ while (in_trans) {
try {
- System.out.println("-sleeping-"); /* trace */
+ System.out.println("-sleeping-"); /* trace */
Thread.sleep(100);
- }
- catch (InterruptedException e) {
- }
}
+ catch(InterruptedException e) {
+ }
+ }
in_trans = true;
- }
+ }
/* release the lock */
public void EndTrans() {
in_trans = false;
- }
+ }
/* perform an autonomous server transaction */
public String ServTrans(String ServCmd) {
- String buf;
+ String buf;
BeginTrans();
buf = DataTrans(ServCmd);
EndTrans();
return buf;
- }
+ }
/* perform a non-autonomous server transaction */
public String DataTrans(String ServCmd) {
/* perform the transaction */
- System.out.println(">"+ServCmd); /* trace */
+ System.out.println(">" + ServCmd); /* trace */
ServPuts(ServCmd);
buf = ServGets();
- System.out.println("<"+buf); /* trace */
+ System.out.println("<" + buf); /* trace */
- try {
- if (buf.startsWith("4")) {
- ofp.writeBytes(TransBuf);
- if (!TransBuf.endsWith("\n")) {
- ofp.writeBytes("\n");
+ try {
+ if (buf.startsWith("4")) {
+ ofp.writeBytes(TransBuf);
+ if (!TransBuf.endsWith("\n")) {
+ ofp.writeBytes("\n");
}
- ofp.writeBytes("000");
- TransBuf = "";
+ ofp.writeBytes("000");
+ TransBuf = "";
}
- if (buf.startsWith("1")) {
- TransBuf = "";
- inbuf = "";
- do {
- inbuf = ServGets();
- if (!TransBuf.equals("")) {
- TransBuf = TransBuf + "\n";
+ if (buf.startsWith("1")) {
+ TransBuf = "";
+ inbuf = "";
+ do {
+ inbuf = ServGets();
+ if (!TransBuf.equals("")) {
+ TransBuf = TransBuf + "\n";
}
- if (!inbuf.equals("000")) {
- TransBuf = TransBuf + inbuf;
+ if (!inbuf.equals("000")) {
+ TransBuf =
+ TransBuf + inbuf;
}
} while (!inbuf.equals("000"));
}
- }
- catch(IOException e) {
- System.out.println(e);
}
-
- return(buf);
+ catch(IOException e) {
+ System.out.println(e);
}
+ return (buf);
+ }
+
public void AddClientThread(Thread ct) {
ClientThreads.addElement(ct);
System.out.println("--new thread registered--");
- }
+ }
public void RemoveClientThread(Thread ct) {
ClientThreads.removeElement(ct);
System.out.println("--thread removed--");
- }
+ }
*/
public void SetUserName(String U) {
PrimaryServerUser = U;
- }
-
+ }
+
public void SetPassword(String P) {
PrimaryServerPassword = P;
- }
+ }
public String GetUserName() {
return PrimaryServerUser;
- }
+ }
public String GetPassword() {
return PrimaryServerPassword;
- }
-
-
-
}
+
+}