Alex Kirk

Ranch Hand
+ Follow
since Aug 13, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Alex Kirk

Yes, it is on a single-CPU box. How would I be blocked by the BufferedReader call?
FYI, this is what prints out when I run it:
Attempting to connect socket to port 7334...
Connected to socket: port 7334
Gnutonic 0.1 at your service

Alex
23 years ago
Or even www.schnarff.com/gnutonic (as in without the comma that makes you get a 404).
Alex
23 years ago
Better yet, go to www.schnarff.com/gnutonic/, and you can see my code there. You'll be interested in connectionManager.java and runGnutonic.java.
Alex
23 years ago
When I launch, I see this:
Attempting to connect socket to port 7334...
Connected to socket: port 7334
Gnutonic 0.1 at your service
The first two lines are from connectionManager's constructor, which goes out and grabs a socket to communicate on.
Alex
23 years ago
Well, it is "public void run()"...but I'll let you look at what's going on here:

Hopefully that will help.
Alex
[This message has been edited by Cindy Glass (edited September 28, 2001).]
23 years ago
Pardon my replication; I've posted a variant of this question on this board before, but now I understand the nature of my problem better, thus this post.
Basically, I've got a program which creates a new thread from a class that extends Thread. The program instantiates an object of that class (successfully -- everything in the constructor works OK), and then calls objectName.start().
For some reason, the run() method of the class is not executed at that point. I've double-checked that it's not some programming error in the method by making run()'s first action a simple System.out.println("Running..."); call, which should show up regardless of what else is going on in the method. The rest of the main program, which calls this class, continues to execute after calling objectName.start(), and has no apparent problems.
FYI, I'm using JDK 1.2 under Linux Emulation on OpenBSD 2.9. The same problem has occured under JDK 1.2 on Win98/2000 as well, so I doubt it's the OS.
Thanks,
Alex Kirk
23 years ago
Where might I find documentation on such wonderful things?
Alex
23 years ago
Is there an equivalent of Python's repr() function (prepares data for the screen) in Java? Specifically, I'd like to print out byte arrays, but only if they contain valid characters (i.e., I don't want a bunch of ASCII gobbledygook messing up my terminal).
Thanks,
Alex Kirk
23 years ago
That's fine and dandy in this little test scenario, but it won't really help me in my real application.
For example, this application has a class connectionManager, which extends Thread. I need it to do so to handle traffic on a UDP Socket in the background. I instantiate it and .start() it from class runGnutonic, which has objects like a configurationManager that I'd like to access.
How could I either a) call a method of or b) grab public data from runGnuonic, while within connectionManager?
Alex
23 years ago
Let me clarify with some code.
{
public int x = 0;
public static void main(String args[])
{
System.out.println("running...");
test2 t = new test2();
t.check();
}
}

{
public void check()
{
System.out.println(super.x);
}
}
When I attempt to run test.java, I get:
./test2.java:5: No variable x defined in class java.lang.Object.
System.out.println(super.x);
^
Does that make more sense?
Sorry for the confusion.
Alex
23 years ago
I've been working on a network app for a while now that uses a class, connectionManager, which runs as a thread and processes inbound and outbound DatagramPackets. It's been behaving progressively more oddly on me the last few days, it's to the point that it's driving me nuts.
On a theoretical level, I know that if I have a class that "extends Thread", whose constructor creates a socket and whose run() method is a while(true) loop, that that class should be able to process all inbound and outbound packets on that socket. Thankfully, outbound packets work just great.
But when I instantiate an object of this class, and then call obj.start(), I'm not receiving anything on this socket (or at least the run() method isn't doing anything with the data that might come in).
Confusing me further are the facts that a) I didn't change anything from the time this worked to now, at least that's related to inbound data packets; and b) if I call obj.run() directly, the program receives data just fine.
To see the files in question, go to www.schnarff.com/gnutonic/runGnutonic.java (the calling, main file) and www.schnarff.com/gnutonic/connectionManager.java (the thread implementation). If you want to try running the program, grab www.schnarff.com/gnutonic/gnutonic-0.1.1.tgz and follow the instructions in the README file.
Thanks for your help.
Alex Kirk
23 years ago
Ummm, nope. That actually calls the superclass of a class; i.e., for java.lang.String, it calls java.lang.Object.
I'm talking about instantiated objects, just to be clear.
Alex
23 years ago
Awww, shit....
It's a static final int...but it'd work just fine if I was having my connection attempt use (ourSock + x).
I really should have seen that.
Thanks,
Alex
Should have been more clear. I defined "x" earlier to be 0; as you'll note, I use it to do the incrementing.
Alex
While writing a network application, I decided to set myself up so that if the port I wanted was already in use, the app would try the port + 1, infinitely until an available port was found.
So I wrote the following code into the constructor of my connectionManager object:
boolean err = false;
do
{
try
{
System.out.println("Attempting to connect socket to port " + (ourSock + x) + "...");
socket = new DatagramSocket(ourSock);
System.out.println("Connected to socket: port " + (ourSock + x));
err = false;
}
catch (SocketException e)
{
System.err.println("Could not connect to port " + (ourSock + x));
System.err.println(e);
x++;
err = true;
}
}
while (err == true);
The code itself seems to work all right. When the port is available, the program connects and is happy; when it's not, it goes up by one numer and attempts to connect again.
The problem is, for some reason Java (or my system, or whatever) thinks that ports which I know to be open aren't. In fact, when my program encounters the first used port, it goes into an infinite loop, wherein it finds that each subsequent port is already in use. Since I've started with port 7334, I know that, say, 7335-7500 are open.
Why would this happen? I'm running Java 2 on an OpenBSD 2.9, Intel-based machine.
Thanks,
Alex Kirk
23 years ago