Name: jn10789 Date: 11/20/98
These steps seem to run fine on NT 4.0, but broadcast packets are not received on Sun Solaris ("uname -a" returns "SunOS wally 5.5.1 Generic_103640-17 sun4m sparc SUNW,SPARCstation-10")
1. On machine 1, type "java Server ip port", where ip is the ip address of the interface that will be receiving datagrams. This machine should be a Solaris machine.
2. On machine 2, type "java Broadcaster ip port", where ip and port are the ip and port used in step 1. At this point you should see messages that indicate that packets are being sent and received.
3. Stop the broadcaster on machine 2 and re-run the broadcaster, specifying a broadcast address for the ip (e.g. 164.217.255.255). The broadcaster will indicate that it is sending packets, but machine 1 will not be receiving them.
Server.java:
package SocketTest;
import java.net.*;
import java.io.*;
public class Server
{
public Server()
{
}
public static void main(String[] args)
{
Server server = new Server();
server.invokedStandalone = true;
if (args.length < 2)
{
System.out.println ("Usage: Server IP port");
return;
}
InetAddress a;
try
{
a = InetAddress.getByName (args [0]);
}
catch (UnknownHostException uhe)
{
System.out.println (args [0] + " is an unknown interface");
return;
}
Integer port = new Integer (args [1]);
DatagramSocket serverSocket;
try
{
serverSocket = new DatagramSocket (port.intValue (), a);
}
catch (IOException ioe)
{
System.out.println ("IO exception on ServerSocket: '" + ioe.toString () + "'");
return;
}
System.out.println ("Socket opened");
boolean quit = false;
byte [] bytes = new byte [512];
int numPackets = 0;
while (!quit)
{
DatagramPacket dp = new DatagramPacket (bytes, 512);
try
{
serverSocket.receive (dp);
}
catch (IOException ioe)
{
System.out.println ("IO exception on accept: '" + ioe.toString () + "'");
return;
}
++numPackets;
System.out.println ("Packets received:" + numPackets);
}
serverSocket.close ();
}
private boolean invokedStandalone = false;
}
Broadcaster.java:
package SocketTest;
import java.net.*;
import java.io.*;
public class Broadcaster
{
public Broadcaster()
{
}
public static void main(String[] args)
{
Broadcaster broadcaster = new Broadcaster();
broadcaster.invokedStandalone = true;
if (args.length < 2)
{
System.out.println ("Usage: Broadcaster IP port");
return;
}
InetAddress dest;
try
{
dest = InetAddress.getByName (args [0]);
}
catch (UnknownHostException uhe)
{
System.out.println (args [0] + " is an unknown interface");
return;
}
int port = (new Integer (args [1])).intValue ();
DatagramSocket socket;
try
{
socket = new DatagramSocket ();
}
catch (IOException ioe)
{
System.out.println ("IO exception on ServerSocket: '" + ioe.toString () + "'");
return;
}
System.out.println ("Opened socket");
boolean quit = false;
byte [] bytes = new byte [512];
int numPackets = 0;
while (!quit)
{
DatagramPacket dp = new DatagramPacket (bytes, 512, dest, port);
try
{
socket.send (dp);
}
catch (IOException ioe)
{
System.out.println ("IO exception on send: '" + ioe.toString () + "'");
return;
}
++numPackets;
System.out.println ("Packets sent:" + numPackets);
}
socket.close ();
}
private boolean invokedStandalone = false;
}
(Review ID: 36115)
======================================================================
- relates to
-
JDK-4212324 Packets sent to broadcast address not received on servers bound to specific addr
- Open