0
votes

I have a this code running on the sending side of a C# .NET socket-based application:

const int port = 1110;
System.Net.Sockets.UdpClient udp = null;

udp = new System.Net.Sockets.UdpClient(host, port);
...
byte[] data = m.Serialize();
udp.Send(data, data.Length);

And I have this code running on the receiving side:

System.Net.IPEndPoint replyAddress = new System.Net.IPEndPoint(
    System.Net.IPAddress.Any, port);
while ((udp != null) && (udp.Available > 0))
{
   ...
}

I have added an exception to the (Windows 7) firewall on the receiving end on UDP port 1110. However, the receiving side code never goes into the while loop unless I completely disable the firewall. Why is the port 1110 exception not taking effect? Using Microsoft Network Monitor, I can see messages trying to come in on port 1110 with a description like UDP:SrcPort = 1082, DstPort = 1110, Length = 11 (I think network monitor sees all messages on the local network, not just those that pass the firewall and are destined for the local system), but unless I disable the firewall completely, my application never receives them.

How can I figure out what's going on here or fix it? I can have a breakpoint set inside the loop, and have the other side sending data, and the moment I disable the firewall, I hit the breakpoint, so I know the traffic can get through, but something about the firewall is preventing it. My firewall exception looks like this:

General

  • Enabled: True
  • Action: Allow the connection

Programs and Services

  • All programs that meed the specified conditions
  • Apply to all programs and services

Computers

  • (Unchecked & empty) Only allow connections from these computers
  • (Unchecked & empty) Skip this rule for connections from these computers

Protocols and Ports

  • Protocol type: UDP
  • Protocol number: 17
  • Local port: Specific Ports
  • Port: 1110
  • Remote port: All Ports

Scope

  • Local IP address: Any IP address
  • Remote IP address: Any IP address

Advanced

  • Specify profiles to which this rule applies: Domain, Private, Public (all checked)
  • Edge traversal: Allow edge traversal

Users

  • Authorized users: (Unchecked & empty) Only allow connections from these users
  • Exceptions: (Unchecked & empty) Skip this rule for connections from these users
1
Are you sure you don't have higher priority blocking rule?Anri
@Anri Turns out that was the problem.BlueMonkMN

1 Answers

1
votes

After further searching of the firewall rules I discovered there was another rule to explicitly block the receiving program based on its path. When Windows pops up a message about a program wanting network access, I guess you have to be careful about how you respond. I intended to temporarily disallow access or cancel the operation (I hadn't intended to run the program yet at the time). But once my response was taken, Windows added a rule to permanently block all access by that program. Deleting those rules allowed the UDP communication to get through the firewall as expected.