The included test case is from Eric Petersen of Ascend:
###@###.### (Eric Petersen)
It demonstrates the fact that you can not send a packet to
the broacast address. 255.255.255.0. I reproduced this on
Solaris.
import java.awt.*;
import java.net.*;
import java.io.*;
public class Test implements Runnable
{
public static void main(String args[])
{
MyFrame win = new MyFrame();
win.show();
}
public void run()
{
}
}
class MyFrame extends Frame
{
TextField dataField=null;
Button bcastBtn=null;
public MyFrame()
{
super("Type some data to broadcast...");
setLayout(new FlowLayout(FlowLayout.LEFT,6,6));
setFont(new Font("Helvetica", Font.PLAIN, 11));
dataField = new TextField(20);
add("Data",dataField);
bcastBtn = new Button("Broadcast");
add("Broadcast",bcastBtn);
pack();
}
public synchronized void show()
{
super.show();
}
public boolean handleEvent(Event ev) {
if(ev.target instanceof Button)
{
doBroadcast();
}
if(ev.id == Event.WINDOW_DESTROY)
{
hide();
dispose();
System.exit(0);
return true;
}
return super.handleEvent(ev);
}
public boolean doBroadcast()
{
try
{
// Open a UDP socket for broadcasting
DatagramSocket socket = new DatagramSocket();
InetAddress localhost = InetAddress.getLocalHost();
System.out.println("Local Host "+localhost.toString());
int bufLen = dataField.getText().length();
byte[] buf = new byte[bufLen];
// Broadcast (address 255.255.255.255, correct?)
DatagramPacket packet = new DatagramPacket(buf,bufLen,
// InetAddress.getByName("255.255.255.0"),1000);
InetAddress.getByName("129.148.27.255" ),1000);
socket.send(packet);
}
catch( Exception e)
{
System.out.println("Exception: "+e.getMessage());
e.printStackTrace();
return false;
}
return true;
}
}
###@###.### (Eric Petersen)
It demonstrates the fact that you can not send a packet to
the broacast address. 255.255.255.0. I reproduced this on
Solaris.
import java.awt.*;
import java.net.*;
import java.io.*;
public class Test implements Runnable
{
public static void main(String args[])
{
MyFrame win = new MyFrame();
win.show();
}
public void run()
{
}
}
class MyFrame extends Frame
{
TextField dataField=null;
Button bcastBtn=null;
public MyFrame()
{
super("Type some data to broadcast...");
setLayout(new FlowLayout(FlowLayout.LEFT,6,6));
setFont(new Font("Helvetica", Font.PLAIN, 11));
dataField = new TextField(20);
add("Data",dataField);
bcastBtn = new Button("Broadcast");
add("Broadcast",bcastBtn);
pack();
}
public synchronized void show()
{
super.show();
}
public boolean handleEvent(Event ev) {
if(ev.target instanceof Button)
{
doBroadcast();
}
if(ev.id == Event.WINDOW_DESTROY)
{
hide();
dispose();
System.exit(0);
return true;
}
return super.handleEvent(ev);
}
public boolean doBroadcast()
{
try
{
// Open a UDP socket for broadcasting
DatagramSocket socket = new DatagramSocket();
InetAddress localhost = InetAddress.getLocalHost();
System.out.println("Local Host "+localhost.toString());
int bufLen = dataField.getText().length();
byte[] buf = new byte[bufLen];
// Broadcast (address 255.255.255.255, correct?)
DatagramPacket packet = new DatagramPacket(buf,bufLen,
// InetAddress.getByName("255.255.255.0"),1000);
InetAddress.getByName("129.148.27.255" ),1000);
socket.send(packet);
}
catch( Exception e)
{
System.out.println("Exception: "+e.getMessage());
e.printStackTrace();
return false;
}
return true;
}
}