Sending UDP Packets 0-40: Troubleshooting Tips

  • Thread starter Thread starter Chrono
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around troubleshooting issues related to sending UDP packets over ports 0 to 40 in a Java program. Participants explore potential problems with the code, address usage, and port number restrictions.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Exploratory

Main Points Raised

  • One participant questions whether the code is missing essential parts or if there is an issue with the address being used.
  • Another participant advises against using port numbers in the range 1-1024, suggesting the use of higher numbers like 5000 instead.
  • Some participants discuss the behavior of UDP packets, noting that they are not guaranteed to be received and may not be sent back if not received.
  • A participant mentions that port 0 does not exist and is reserved, explaining that using it may lead to unexpected behavior.
  • One participant shares their experience of changing the port range from 0-40 to 40-80, which resolved their issue, while also suggesting that security settings may have affected their ability to send packets.

Areas of Agreement / Disagreement

Participants express differing views on the use of specific port numbers and the behavior of UDP packets. There is no consensus on the best approach to resolve the initial issue, and multiple perspectives on the reliability of UDP are presented.

Contextual Notes

Participants highlight limitations regarding the use of reserved ports and the nature of UDP as a best-effort protocol, but do not resolve the implications of these factors on the original problem.

Chrono
Messages
424
Reaction score
3
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);
}
}
}
 
Technology news on Phys.org
Don't use port numbers in the range 1-1024, because they are reserved by the operating system for other services. Couldn't you use bigger numbers, such as 5000?
 
Wouldn't the packets be sent back or rejected anyway?
 
the packets won't be sent back because udp is not a reliable protcol unlike tcp, there is no guarantee that the packet will be received.
 
Chrono said:
Wouldn't the packets be sent back or rejected anyway?

The behavior depends on the operating system, but it is guaranteed that those ports (i.e. 1-40) can't be accessed. By the way, port 0 doesn't exist.

dmail said:
the packets won't be sent back because udp is not a reliable protcol unlike tcp, there is no guarantee that the packet will be received.

UDP is a best-effort protocol, meaning that the most is done to ensure (although not guarantee) a reliable delivery. In practice it is rare that UDP fails.
 
By the way, port 0 doesn't exist.

Well according to RFC's it is reserved, in general networking port 0 is the same as a broadcast address in IP, if you code an app to use port 0 it will try to find the first available UDP port

RFC
Explanation of port 0

because of this 'feature' many security experts recommend that port 0 is blocked
 
Last edited:
I think I got it, guys. Thanks for the help. For one thing I was sending them to localhost. I don't think that would work well on sending packets. Also, I did change the port numbers (by the way, I was told to use ports 0 - 40) to 40 - 80 and it worked just fine. I still think the school's security had some problems with us sending out packets, but eventually we all got it to work. Thanks again!
 

Similar threads

  • · Replies 39 ·
2
Replies
39
Views
8K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 13 ·
Replies
13
Views
7K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
3
Views
3K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 6 ·
Replies
6
Views
6K
  • · Replies 3 ·
Replies
3
Views
13K