Another window management bug
I've just reported this at the JDC. It seems to be specific to Linux,
and affects both the Blackdown and Sun versions of 1.3.1.
Ron
...
java version "1.3.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_01)
Java HotSpot(TM) Client VM (build 1.3.1_01, mixed mode)
Compile and run the enclosed program. It creates a JFrame containing a
button. The first time the button is pressed a JDialog is created
containing a cancel button. Pressing the cancel button hides the
JDialog. Pressing the button in the JFrame again shows the JDialog.
This works as expected on all platforms and versions of Java that I've
tried (including 1.4.0beta2 on Linux), except on Linux with Java 1.3.1
and 1.3.1_01. In these versions the JDialog is iconified when it
reappears.
import javax.swing.*;
import java.awt.event.*;
public class DialogBug extends JFrame {
JDialog dialog ;
public DialogBug() {
super("DialogBug") ;
JButton button = new JButton("Press me") ;
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if ( dialog == null ) {
dialog = new MyDialog(DialogBug.this) ;
}
dialog.setVisible(true) ;
}});
getContentPane().add(button) ;
pack() ;
show() ;
}
public static void main(String[] args) {
new DialogBug() ;
}
private class MyDialog extends JDialog {
public MyDialog(JFrame frame) {
super(frame, "Dialog") ;
JButton cancel = new JButton("Cancel") ;
cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MyDialog.this.setVisible(false) ;
}});
getContentPane().add(cancel, "Center") ;
pack() ;
}
}
}
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Re: DatagramSocket and Thread problem (more)
Hi Dustin Lang,
I have edited your code. It is working fine,
except for few changes.
The sender to the same port you are listening to
else you will get a time out error.
Instead of socket.getLocalAddress().getHostAddress()
use InetAddress. getLocalhost(). The former gives 0.0.0.0.
These make the program work successfully.
Regards
TJP.
Dustin Lang wrote:
Hi again,
Further to my previous message. It seems that the sending thread
is also
bothered by the receiving thread. The first send() succeeds,
but once the
receive thread touches the socket, all further send()s fail with
"IOException: Connection refused". This is a DatagramSocket!
I was under
the impression that this exception should never be thrown by
DatagramSocket.send() - packets are just sent off into the big blue
yonder; if nobody is listening on the destination machine, the packet
should just get tossed into the bit bucket.
Any suggestions would be appreciated.
Cheers,
dstn.
-- Dustin Lang, [EMAIL PROTECTED]
--
User, n.: a particularly slow and unreliable input/
output device that is attached by default to
the
standard input and output streams.
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
-- ---
Tony J. Paul
AdventNet Development Center India (P) Ltd.,
13-A, Velachery Main Road
Velachery Chennai - 600 042
Ph: +91-044-2432414/2748/2749/3484 Ext : 419
Email :[EMAIL PROTECTED]
http://www.adventnet.com
---
When you aim for perfection, you discover it's a moving target. -George
Fisher
import java.net.*;
import java.io.*;
class SocketTest implements Runnable {
DatagramSocket socket;
Thread receiver;
static long time;
public SocketTest() throws IOException {
socket = new DatagramSocket(2000,InetAddress.getLocalHost());
socket.setSoTimeout(5000);
output("Datagram socket open on " + InetAddress.getLocalHost()
+ " port " + socket.getLocalPort() + ".");
receiver = new Thread(this, "Receiver");
receiver.start();
}
public void sendPacket() {
try {
byte[] packetData = new byte[1024];
DatagramPacket packet = new DatagramPacket(packetData, packetData.length,
InetAddress.getLocalHost(), 2000);
output("Sending packet...");
socket.send(packet);
output("Sent packet.");
} catch (Exception e) {
output("Send failed: " + e);
}
}
public void run() {
output("Thread started.");
int packetSize = 1024;
byte[] packetData = new byte[packetSize];
DatagramPacket packet = new DatagramPacket(packetData, packetSize);
for (;;) {
output("Receiving packet...");
try {
socket.receive(packet);
} catch (InterruptedIOException ie) {
output("Receive timed out.");
} catch (IOException ioe) {
output("IO Exception: " + ioe);
output("Stack trace:");
output("-");
ioe.printStackTrace();
output("-");
}
try {
Thread.sleep(5000);
} catch (InterruptedException ie) {
}
}
}
static void output(String s) {
System.out.println("[" + Thread.currentThread().getName() + " "
+ ((System.currentTimeMillis()-time)/1000) + "]: " + s);
}
public static void main(String[] args) {
Thread.currentThread().setName("Sender ");
time = System.currentTimeMillis();
try {
SocketTest st = new SocketTest();
for (;;) {
st.sendPacket();
try {
Thread.sleep(7000);
} catch (InterruptedException ie) {
}
}
} catch (IOException ioe) {
output("IO Exception: " + ioe);
ioe.printStackTrace();
}
}
}
Re: Another window management bug
On Tue, 2001-09-25 at 05:31, [EMAIL PROTECTED] wrote:> I've just reported this at the JDC. It seems to be specific to Linux, > and affects both the Blackdown and Sun versions of 1.3.1. > > RonOne more thing. I did see the behavior that you are reporting with KDE. -- Jesse Stockall | Tel: 1+ 613.599.2441 ext. 243 CRYPTOCard Corporation | Fax: 1+ 613.599.2442 Suite 304, 300 March Rd. | email: [EMAIL PROTECTED] Ottawa, ON, Canada K2K 2E2 | web: www.cryptocard.com -
[Fwd: [Fwd: Re: Another window management bug]]
This one didn't get through On Tue, 2001-09-25 at 05:31, [EMAIL PROTECTED] wrote: > I've just reported this at the JDC. It seems to be specific to Linux, > and affects both the Blackdown and Sun versions of 1.3.1. > > Ron > Hmmm It works for me on Linux & Win2000 Debian with Sawfish Blackdown-1.3.1-FCS, J2RE 1.3.0 IBM, Sun build 1.3.1-b24 Win2000 Sun build 1.3.1_01 -- Jesse Stockall | Tel: 1+ 613.599.2441 ext. 243 CRYPTOCard Corporation | Fax: 1+ 613.599.2442 Suite 304, 300 March Rd. | email: [EMAIL PROTECTED] Ottawa, ON, Canada K2K 2E2 | web: www.cryptocard.com - -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Re: Another window management bug
[EMAIL PROTECTED] writes: [Setting a JFrame invisible and then visible iconifies it] Happens on RedHat 6.2 and RedHat 7.1 with with Sun's jdk-1_2_2_008. Norman Shapiro 798 Barron Avenue Palo Alto CA 94306-3109 (650) 565-8215 [EMAIL PROTECTED] -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Re: DatagramSocket and Thread problem
Hi, > I have edited your code. It is working fine, except for few changes. Thanks. However, my original email was essentially a bug report, not a request for help with my code. I didn't actually say "bug report" because so many bug reports end up just being problems with people's code. I believe my code as originally posted was valid (and reasonable!) and that the Blackdown Linux JDK is doing something wrong. The changes you made are the obvious ways to work around this bug. However, there are some remaining problems. You changed socket = new DatagramSocket(); to socket = new DatagramSocket(2000,InetAddress.getLocalHost()); where you have arbitrarily chosen port 2000. I really do want the correct behaviour of the argument-less DatagramSocket() constructor: to pick an unused port. It would be possible to, starting at a random number, look for an unused port, but this is ugly when a constructor that does exactly what I want already exists. > The sender to the same port you are listening to else you will get a time > out error. If I wanted to talk to myself. :) This of course not the point of the exercise. The address I chose for the send() was completely arbitrary. For my application, it will be the address of the server, of course. > Instead of socket.getLocalAddress().getHostAddress() use InetAddress. > getLocalhost(). The former gives 0.0.0.0. Yes, I noticed. If I wanted the address of the local host, I would use InetAddress.getLocalhost(). What I wanted to demonstrate in my small test class was the behaviour of DatagramSocket.getLocalAddress(). The Linux JDK behaviour in this case actually matches the Solaris behaviour. 8-) > These make the program work successfully. By working around the problem. This email might sound rude - it's not meant to be! I'm just pointing out that you're showing me how to work around what I believe is a bug, without addressing whether it actually is a bug, or addressing what to do to fix the bug. After writing this I checked the bug database at java.sun.com. There were several reports of this happening in some flavours of Windoze and one flavour of Redhat. They claim to have fixed the problem in Merlin aka 1.4. The solution is thus simple: wait! Thanks for your response! Cheers, dustin. -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
