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