// messagingClient Class
// UNDER DEVELOPMENT
// Currently Reads All Messages From Server, sends acknowledgement that messages are received
// then loops back and obtains new set of messages
import java.net.*;
import java.io.*;
import java.util.*;
import java.applet.Applet;
import java.awt.*;
public class messagingClient extends Applet implements Runnable
{
Image messageimage;
Graphics messagegraphics;
Thread me;
int xpos;
int ypos;
int textwidth;
String clienttype;
String callcenterid;
Vector messages;
messagingServerInfo server;
Socket connection;
String message;
String endmsg;
int appWidth;
int appHeight;
int FONT_SIZE;
int BK_R;
int BK_G;
int BK_B;
int TXT_R;
int TXT_G;
int TXT_B;
int Y_OFFSET;
String FONT_NAME;
int SPEED;
Color BK;
Color TXT;
public void init()
{
clienttype = getParameter("clienttype"
callcenterid = getParameter("callcenterid"
appWidth = Integer.parseInt(getParameter("appWidth");
appHeight = Integer.parseInt(getParameter("appHeight");
setBackground(Color.black);
messageimage = createImage(appWidth, appHeight);
messagegraphics = messageimage.getGraphics();
FONT_SIZE = Integer.parseInt(getParameter("FONT_SIZE");
FONT_NAME = getParameter("FONT_NAME"
SPEED = Integer.parseInt(getParameter("SPEED");
Y_OFFSET = appHeight/2 - FONT_SIZE/2;
BK_R = Integer.parseInt(getParameter("BK_R");
BK_G = Integer.parseInt(getParameter("BK_G");
BK_B = Integer.parseInt(getParameter("BK_B");
TXT_R = Integer.parseInt(getParameter("TXT_R");
TXT_G = Integer.parseInt(getParameter("TXT_G");
TXT_B = Integer.parseInt(getParameter("TXT_B");
BK = new Color(BK_R, BK_G, BK_B);
TXT = new Color(TXT_R, TXT_G, TXT_B);
xpos = appWidth + 10;
ypos = Y_OFFSET; // position to look right
messages = new Vector();
server = new messagingServerInfo();
connection = null;
message = "MESSAGES AWAIT!";
endmsg = "---- END OF MESSAGES ----";
me = new Thread(this);
me.start();
}
public void paint(Graphics g)
{
messagegraphics.setColor(BK); // Background colour again
messagegraphics.fillRect(0,0,appWidth + 1, appHeight + 1);
messagegraphics.setColor(TXT); // Text colour here
try
{
messagegraphics.setFont(new Font(FONT_NAME,0,FONT_SIZE));
}
catch(NullPointerException _ex) { }
messagegraphics.drawString(message, xpos, ypos);
g.drawImage(messageimage, 0, 0, this);
}
public void update(Graphics g)
{
paint(g);
}
public void run()
{
//connect to Server
try
{
connection = new Socket(server.getServer(), server.getPort());
// System.out.println("Connected To Server"
ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream());
//SEND CLIENT PARAMETERS TO SERVER - SERVER ALWAYS EXPECTS 2 PARAMETERS FROM CLIENTS
try
{
output.flush();
output.writeObject((String)clienttype);
output.flush();
output.writeObject((String)callcenterid);
output.flush();
}
catch(IOException e)
{
//client closed connection early
}
//READ SERVER MESSAGES
while(true) //CONNECTION IS OPEN
{
ObjectInputStream input = new ObjectInputStream(connection.getInputStream());
while(true) //MESSAGES ARE BEING SENT
{
try
{
message = (String)input.readObject();
//If end of messages occurs, break from reading loop
if(message.equals(endmsg))
break;
messages.add(message);
//System.out.println(message);
}
catch(ClassNotFoundException e)
{
//System.out.println("Unknown Object Sent By Server"
}
} //END WHILE(TRUE) MESSAGES ARE BEING SENT
//**** FUTURE AREA OF SCROLLING MESSAGES FROM VECTOR ACROSS APPLET ****
for(int msgnum=0; msgnum < messages.size(); msgnum++)
{
message = (String) messages.elementAt(msgnum);
textwidth = 7 * message.length();
xpos = appWidth + 10;
while(xpos > (textwidth-2*textwidth))
{
xpos--;
try
{
Thread.sleep(SPEED);
}
catch (InterruptedException _ex) { }
repaint();
}
}
xpos = appWidth + 10;
messages.removeAllElements();
//**** AFTER COMPLETED SENDING ONE 'CYCLE', OUTPUT TO SERVER THAT ****
//**** CLIENT IS READY FOR THE NEXT 'CYCLE' ****
ObjectOutputStream ops = new ObjectOutputStream(connection.getOutputStream());
String ready = "CLIENT READY";
ops.writeObject((String)ready);
output.flush();
} //END WHILE(TRUE) CONNECTION IS OPEN
}
catch(UnknownHostException e)
{
//System.out.println("Cannot Find Server"
//System.out.println(e);
//System.exit(1);
}
catch(IOException e)
{
//System.out.println("Server Found, but cannot connect to Server"
//System.out.println(e);
//System.exit(1);
}
} // END RUN
}
// UNDER DEVELOPMENT
// Currently Reads All Messages From Server, sends acknowledgement that messages are received
// then loops back and obtains new set of messages
import java.net.*;
import java.io.*;
import java.util.*;
import java.applet.Applet;
import java.awt.*;
public class messagingClient extends Applet implements Runnable
{
Image messageimage;
Graphics messagegraphics;
Thread me;
int xpos;
int ypos;
int textwidth;
String clienttype;
String callcenterid;
Vector messages;
messagingServerInfo server;
Socket connection;
String message;
String endmsg;
int appWidth;
int appHeight;
int FONT_SIZE;
int BK_R;
int BK_G;
int BK_B;
int TXT_R;
int TXT_G;
int TXT_B;
int Y_OFFSET;
String FONT_NAME;
int SPEED;
Color BK;
Color TXT;
public void init()
{
clienttype = getParameter("clienttype"
callcenterid = getParameter("callcenterid"
appWidth = Integer.parseInt(getParameter("appWidth");
appHeight = Integer.parseInt(getParameter("appHeight");
setBackground(Color.black);
messageimage = createImage(appWidth, appHeight);
messagegraphics = messageimage.getGraphics();
FONT_SIZE = Integer.parseInt(getParameter("FONT_SIZE");
FONT_NAME = getParameter("FONT_NAME"
SPEED = Integer.parseInt(getParameter("SPEED");
Y_OFFSET = appHeight/2 - FONT_SIZE/2;
BK_R = Integer.parseInt(getParameter("BK_R");
BK_G = Integer.parseInt(getParameter("BK_G");
BK_B = Integer.parseInt(getParameter("BK_B");
TXT_R = Integer.parseInt(getParameter("TXT_R");
TXT_G = Integer.parseInt(getParameter("TXT_G");
TXT_B = Integer.parseInt(getParameter("TXT_B");
BK = new Color(BK_R, BK_G, BK_B);
TXT = new Color(TXT_R, TXT_G, TXT_B);
xpos = appWidth + 10;
ypos = Y_OFFSET; // position to look right
messages = new Vector();
server = new messagingServerInfo();
connection = null;
message = "MESSAGES AWAIT!";
endmsg = "---- END OF MESSAGES ----";
me = new Thread(this);
me.start();
}
public void paint(Graphics g)
{
messagegraphics.setColor(BK); // Background colour again
messagegraphics.fillRect(0,0,appWidth + 1, appHeight + 1);
messagegraphics.setColor(TXT); // Text colour here
try
{
messagegraphics.setFont(new Font(FONT_NAME,0,FONT_SIZE));
}
catch(NullPointerException _ex) { }
messagegraphics.drawString(message, xpos, ypos);
g.drawImage(messageimage, 0, 0, this);
}
public void update(Graphics g)
{
paint(g);
}
public void run()
{
//connect to Server
try
{
connection = new Socket(server.getServer(), server.getPort());
// System.out.println("Connected To Server"
ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream());
//SEND CLIENT PARAMETERS TO SERVER - SERVER ALWAYS EXPECTS 2 PARAMETERS FROM CLIENTS
try
{
output.flush();
output.writeObject((String)clienttype);
output.flush();
output.writeObject((String)callcenterid);
output.flush();
}
catch(IOException e)
{
//client closed connection early
}
//READ SERVER MESSAGES
while(true) //CONNECTION IS OPEN
{
ObjectInputStream input = new ObjectInputStream(connection.getInputStream());
while(true) //MESSAGES ARE BEING SENT
{
try
{
message = (String)input.readObject();
//If end of messages occurs, break from reading loop
if(message.equals(endmsg))
break;
messages.add(message);
//System.out.println(message);
}
catch(ClassNotFoundException e)
{
//System.out.println("Unknown Object Sent By Server"
}
} //END WHILE(TRUE) MESSAGES ARE BEING SENT
//**** FUTURE AREA OF SCROLLING MESSAGES FROM VECTOR ACROSS APPLET ****
for(int msgnum=0; msgnum < messages.size(); msgnum++)
{
message = (String) messages.elementAt(msgnum);
textwidth = 7 * message.length();
xpos = appWidth + 10;
while(xpos > (textwidth-2*textwidth))
{
xpos--;
try
{
Thread.sleep(SPEED);
}
catch (InterruptedException _ex) { }
repaint();
}
}
xpos = appWidth + 10;
messages.removeAllElements();
//**** AFTER COMPLETED SENDING ONE 'CYCLE', OUTPUT TO SERVER THAT ****
//**** CLIENT IS READY FOR THE NEXT 'CYCLE' ****
ObjectOutputStream ops = new ObjectOutputStream(connection.getOutputStream());
String ready = "CLIENT READY";
ops.writeObject((String)ready);
output.flush();
} //END WHILE(TRUE) CONNECTION IS OPEN
}
catch(UnknownHostException e)
{
//System.out.println("Cannot Find Server"
//System.out.println(e);
//System.exit(1);
}
catch(IOException e)
{
//System.out.println("Server Found, but cannot connect to Server"
//System.out.println(e);
//System.exit(1);
}
} // END RUN
}