C# (UDP communication) Program runs on Laptop but not on antoher Computer

Candiag Candiag 1 Reputation point
2021-06-08T00:22:22.683+00:00

Some background on what I'm doing. I have a laptop (running VS2017) where I wrote a simple C# program (using UDPClient( ) ) to read UDP traffic sent from a microcontroller that communicates over Ethernet. The microcontroller uses port 8080 when it sends out UDP traffic to the laptop.

The program works fine when I execute it on my laptop (via VS2017 debug mode). When I try to run the application on another machine I cannot receive UDP traffic anymore. The 2 ways I've deployed the application to the new machine are,

  1. Using the App package generator in VS2017
  2. Creating a release build in VS2017 and copying the release folder to the destination machine.

Both methods allow the program to run (2nd computer) but NOT receive UDP traffic transmitted by the Microcontroller

I'm adding the most relevant code for review
The function below is part of a bigger class. I use it to setup the IpEndPt. The function is called with UDP_Port = 8080. So you sit and wait on port 8080 until the microcontroler sends UDP traffic to the laptop

SETUP UdpClient( )
public TCP_UDP_Comm(int UDP_Port)
{
IPEndPoint IpEndPt = new IPEndPoint(IPAddress.Any, UDP_Port);
UdpSock = new UdpClient(IpEndPt);

}

This is the function that receives UDP traffic communicated from the microcontroller
public async void LoopInfinitelyFor_UDP_Traffic()
{
while (true)
{
try
{
// Sit here and wait till a client connects
var RecResult = await UdpSock.ReceiveAsync();

      string Response = Encoding.ASCII.GetString(RecResult.Buffer);

      IPEndPoint ClientEndPoint = RecResult.RemoteEndPoint;


      // Fire a textbox update event -- Received some data from a microcontroller
      // The viewmodel code receives the event
      // it will then update the text box property

      RaiseEvent(this, new UDP_Event_Args.UDP_Event_Args() { TextToShow = Response });                                           
      string RemoteClientIP_Addr = ClientEndPoint.Address.ToString();
      int RemoteCLient_Port = ClientEndPoint.Port;

    } 

}

}

The target machine has the latest .NET framework installed. I plan to install VS2017 on that machine to try and debug. The puzzling question is why this works fine on my Laptop (where VS2017) is installed yet when I deploy to a new machine the program fails to receive UDP traffic

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,774 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,927 questions
{count} votes

3 answers

Sort by: Most helpful
  1. AgaveJoe 28,371 Reputation points
    2021-06-09T14:25:56+00:00

    Before I ran the program on the second machine I made sure to set the Ethernet port to 192.168.7.99

    That seems a little iffy. Assuming this is a home network, the router keeps track of which IP goes with which MAC address. Did you reset the router or check the routing table?

    1 person found this answer helpful.
    0 comments No comments

  2. Candiag Candiag 1 Reputation point
    2021-07-01T03:36:39.767+00:00

    Emon Haque1485 guided me to the solution. It turns out I had to open port 8080 in Windows defender. I must have done this on the machine that had the working program but forgot I did it. Yes it’s not the safest thing to do but these machines are not connected to any network.

    Thanks to all those who responded. Your suggestions allowed me to resolve my problem.

    Thanks,
    Candiago

    0 comments No comments

  3. Sulabh Srivastava 1 Reputation point
    2022-10-16T02:10:16.993+00:00

    Hi, I have similar issue but in my case firewall is open as I can receive message using other app which is not built on visual studio 2017, but I face issue when I build with 2017.

    I posted question but couldn't get any clue how to resolve this.

    Please check if you can help.
    https://learn.microsoft.com/en-us/answers/questions/1030287/udp-issue-with-visual-studio-2017-application.html

    Thanks

    0 comments No comments

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.