C# How to send UDP packets between 2 computer with dedicated NICs (no router)

Steve Cobb 0 Reputation points
2024-02-18T22:58:01.7133333+00:00

I have 2 computers connected via built in NICs to a router connected to the web. Each computer has a second dedicated NIC on a different sub-net - connected directly to each other (no router). Device A (Sender)  IPv4 Address. . . . . . . . . . . : 192.168.1.21  built in NIC - connected to internet IPv4 Address. . . . . . . . . . . : 192.168.0.121  SFP NIC card connected directly to device B Device B (Receiver)  IPv4 Address. . . . . . . . . . . : 192.168.1.173  built in NIC - connected to internet IPv4 Address. . . . . . . . . . . : 192.168.0.122  SFP NIC card connected directly to device A

I have a sending app on Device A and receiving app on Device B. I can ping from Device A to B just fine using either 192.168.1.173 or 192.168.0.122 - so the connection is fine.

// Sending side
Socket socket = 
byte
IPAddress receiver_address = 
IPEndPoint receiver = 
int
IPEndPoint local = (IPEndPoint)
Console
// Receiving side
Socket socket = 
IPEndPoint receiver = 
socket

byte
IPEndPoint peer = 
EndPoint peer_ref = (EndPoint)

int
string
peer
IPEndPoint local = (IPEndPoint)
Console

So, Running the sender code to 192.168.1.173 works fine. Ping works both ways between 192.168.0.121 and 192.168.0.122. So the connection is good. However, Running the sender code to 192.168.0.122 does not get received by the receiver program. Wireshark does show the packets arriving at 192.168.0.122 - so the packets are getting there. Why does the receiver not see the packets when sent from 192.168.0.121 to 192.168.0.122?  It seems the sender is set correctly as the path works and WireShark sees the packets. It seems the receiver is configured incorrectly or looking only at the wrong interface.  I’m sure it is something simple. Do I need to bind the receiver to the sub-net or NIC interface?

Developer technologies | C#
{count} votes

1 answer

Sort by: Most helpful
  1. Jiachen Li-MSFT 34,221 Reputation points Microsoft External Staff
    2024-02-19T09:53:32.35+00:00

    Hi @Steve Cobb ,

    Here are some suggestions for checks that may be useful.

    1. Check Receiving Application Configuration: Revisit the configuration of the receiving application on Device B. Ensure that it is listening on the correct IP address (192.168.0.122) and port number. Verify that there are no restrictions or filters in the application code that may prevent it from processing incoming packets.
    2. Verify Packet Contents: Use Wireshark to inspect the contents of the received packets. Ensure that the packets contain the expected data and are formatted correctly. If there are any discrepancies, it could indicate issues with the sending application or the packet content itself.
    3. Network Interface Configuration: Double-check the network interface configuration on Device B. Ensure that the network interface corresponding to 192.168.0.122 is properly configured and active. Verify that there are no conflicting network settings or issues with the network adapter driver.
    4. Firewall and Security Software: Review the firewall and security software settings on Device B. Ensure that they are not blocking or interfering with the incoming UDP traffic on port 192.168.0.122. Temporarily disable any firewall or security software to see if it resolves the issue.
    5. Debugging the Receiving Application: Add debugging statements or logging to the receiving application code to trace the flow of incoming packets and identify any errors or issues in the processing logic. This can help pinpoint where the problem is occurring within the application.

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.