Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JavaBeans OCX

Status
Not open for further replies.

cpope

Programmer
Jul 7, 2000
58
0
0
US
I have recently created a client/server message board system. The client piece was originally developed as an Applet, but due to security issues surrounding sockets, I needed to come up with another solution. I couldn't find an easy way or a clear description to sign the applet on all client machines automatically. I decided instead on converting the applet to a JavaBean and to run the bridge to convert the Bean into an OCX. I can add this OCX into a VB window no problem, and starting the VB app causes no problems. But for some reason, the bean is not initializing, it never attempts to connect to the server? Is there something I am missing?? Here is the code:

// messagingClient Class
// 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.awt.*;

public class messagingClient extends Panel implements Runnable, Serializable
{
static final long serialVersionUID = 4325646018653553462L;
int xpos;
int ypos;
int textwidth;
String clienttype;
String callcenterid;
Vector messages;
String server;
int port;
Socket connection;
String message;
String endmsg;
int appWidth;
int appHeight;
transient Thread me;


public void writeObject(ObjectOutputStream out) throws IOException
{
out.defaultWriteObject();
}

public void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
{
in.defaultReadObject();
me = new Thread(this);
initVars();
start();
}

public void start()
{
if(me==null)
{
me = new Thread(this);
initVars();
me.start();
}

}

public void setcallcenterid(String callcenterid)
{
this.callcenterid = callcenterid;
}

public String getcallcenterid()
{
return this.callcenterid;
}

public void setappWidth(int appWidth)
{
this.appWidth = appWidth;
}

public int getappWidth()
{
return this.appWidth;
}

public void setappHeight(int appHeight)
{
this.appHeight = appHeight;
}

public int getappHeight()
{
return this.appHeight;
}

public void setclienttype(String clienttype)
{
this.clienttype = clienttype;
}

public String getclienttype()
{
return this.clienttype;
}

public void setserver(String server)
{
this.server = server;
}

public String getserver()
{
return this.server;
}

public void setport(int port)
{
this.port = port;
}

public int getport()
{
return this.port;
}

private void initVars()
{
if(clienttype==null)
clienttype = "USER";
if(callcenterid==null)
callcenterid = "OH0001";
if(appWidth==0)
appWidth = 400;
if(appHeight==0)
appHeight = 14;
if(server==null)
server = "p3000883";
if(port==0)
port = 1550;
messages = new Vector();
connection = null;
message = "MESSAGES AWAIT!";
endmsg = "---- END OF MESSAGES ----";
setBackground(Color.black);
xpos = appWidth + 10;
ypos = 12; // position to look right

}

public messagingClient()
{
//DECLARE DEFAULT VALUES
if(clienttype==null)
clienttype = "USER";
if(callcenterid==null)
callcenterid = "OH0001";
if(appWidth==0)
appWidth = 400;
if(appHeight==0)
appHeight = 14;
if(server==null)
server = "p3000883";
if(port==0)
port = 1550;
messages = new Vector();
connection = null;
message = "MESSAGES AWAIT!";
endmsg = "---- END OF MESSAGES ----";
setBackground(Color.black);
xpos = appWidth + 10;
ypos = 12; // position to look right
start();
}

public void paint(Graphics g)
{
g.setColor(Color.black); // Background colour again
g.fillRect(0,0,appWidth + 1, appHeight + 1);
g.setColor(Color.white); // Text colour here
try
{
g.setFont(new Font("Arial",0,10)); // change font or font size (Fontname, 0, Size)
}
catch(NullPointerException _ex) { }
g.drawString(message, xpos, ypos);
}

public void update(Graphics g)
{
paint(g);
}

public void run()
{

//connect to Server
try
{
connection = new Socket(server, port);
// 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


//**** SCROLLING MESSAGES FROM VECTOR ACROSS APP ****
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(10);
}
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 = &quot;CLIENT READY&quot;;
ops.writeObject((String)ready);
output.flush();

} //END WHILE(TRUE) CONNECTION IS OPEN
}
catch(UnknownHostException e)
{
//System.out.println(&quot;Cannot Find Server&quot;);
//System.out.println(e);
//System.exit(1);
}
catch(IOException e)
{
//System.out.println(&quot;Server Found, but cannot connect to Server&quot;);
//System.out.println(&quot;Server software not running or maximum connections to Server have been reached&quot;);
//System.out.println(e);
//System.exit(1);
}

} // END RUN

}
 
Does it need to be registered like other ocx files i.e. like ActiveX?
 
The bridge that comes with the BDK automatically registers the OCX. I can add it to a VB application easily, but when the application is run, the Bean does not initialize (but it does not cause any errors or crashes either). This has me pretty confused?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top