- #1
Chrono
- 425
- 2
All right, guys. The code below is supposed to send UDP packets over the ports 0 - 40. However, when I run it, it doesn't seem to send anything. I'm guessing it's one of two things: I'm missing some essential part of the code, or that something's wrong with the address. Anybody have any ideas?
Code:
import java.net.*;
import java.io.*;
public class datagram
{
public static void main(String args[]) throws Exception
{
int i;
byte[] buf = new byte[256];
DatagramSocket socket;
DatagramPacket packet;
InetAddress address = InetAddress.getByName("localhost");
for(i = 0; i <= 40; i++)
{
socket = new DatagramSocket(i);
packet = new DatagramPacket(buf, buf.length, address, i);
socket.send(packet);
}
}
}