|
From: Jim H. <Ha...@ma...> - 2003-04-08 18:58:19
|
I have no Java experience, actually no experience outside of Python and no
OO experience either, but I have to use a Java toolkit.
So, I am trying to convert the sample Java file (appended below) into
Jython.
My Jython file and the error message are also appended below.
I have no idea what the expected 2nd argument is since only one is passed in
the example.
Any help would be appreciated.
ERROR MESSAGE
Traceback (innermost last):
File "SimpleTest.py", line 26, in ?
TypeError: addConnectionListener(): expected 2 args; got 1
MY JYTHON FILE (SimpleTest.py)
import com.newsedge.live.toolkit.receiver
from com.newsedge.live.toolkit.receiver import ConnectionListener
class ConnectionStatusMonitor(ConnectionListener):
def connectionEstablished(self, ipAddress, port, clientName):
print "Connected to %s/%i as %s"%(ipAddress, port, clientName)
def connectionBroken(self):
print "Connection broken."
def connectionUnavailable(self):
print "Connection unavailable."
if __name__ == '__main__':
liveNews = com.newsedge.live.toolkit.receiver.LiveNews
liveNews.addConnectionListener(ConnectionStatusMonitor())
SAMPLE JAVA FILE
import java.io.*;
import com.newsedge.live.toolkit.receiver.*;
public class SimpleTest {
private LiveNews liveNews;
public SimpleTest (String[] args)
{
try
{
liveNews = new LiveNews ();
liveNews.addConnectionListener (new ConnectionStatusMonitor ());
// Get the arguments.
String clientName = args[0];
String password = args[1];
boolean useTunneling = args[2].equals ("true");
System.out.println ("Connecting to a Push Engine...");
liveNews.connect (clientName, password, useTunneling);
}
catch (ConnectException connectException)
{
System.out.println (connectException);
}
catch (IOException ioException)
{
System.out.println (ioException);
}
}
public static void main (String[] args)
{
if (args.length != 3)
{
// For example, "java SimpleTest henry myPassword false".
System.out.println ("Usage: java SimpleTest <ClientName> <Password>
<Tunneling>");
System.exit (0);
}
SimpleTest test = new SimpleTest (args);
}
private class ConnectionStatusMonitor implements ConnectionListener {
public ConnectionStatusMonitor ()
{
}
// This method is called when a connection has been established.
public void connectionEstablished (String ipAddress, int port, String
clientName)
{
System.out.println ("Connected to " + ipAddress + "/" + port + " as "
+ clientName);
}
// The method is called when a connection has been broken.
public void connectionBroken ()
{
System.out.println ("Connection broken");
}
// The method is called when no connection is available. This may be
// called during a failover attempt.
public void connectionUnavailable ()
{
System.out.println ("Connection unavailable");
}
}
}
Thanks very much for any help,
Jim Haak
|