Sending and Receiving Broadcast Messages

Guys I need help here. I am doing a project in C # where data needs to be sent as a datagram and also receive data that is being broadcast.

Below is the code:

  public void StartUdpListener(Object state)
    {

        receivedNotification = udpServer.Receive(ref remoteEndPoint);
        notificationReceived = Encoding.ASCII.GetString(receivedNotification);

        listBox = new StringBuilder(this.listBox1.Text);
        listBox.AppendLine(notificationReceived);


        if (listBox1.InvokeRequired)
        {
            this.Invoke((MethodInvoker)delegate { this.listBox1.Items.Add(listBox.ToString()); });
        }



    }

    public void StartNotification()
    {

        ThreadPool.QueueUserWorkItem(new WaitCallback(StartUdpListener));

        hostName = Dns.GetHostName();
        hostBuffer = Encoding.ASCII.GetBytes(hostName);

        UdpClient newUdpClient = new UdpClient();
        newUdpClient.Send(hostBuffer, hostBuffer.Length, notifyIP);



    }

      

Could you guys tell me that the code is fine because there is no one with whom I can test the code on lan Thanks to the tuners.

0


a source to share


1 answer


Why don't you set up your own broadcaster and listener in individual cases.



This is a great article on socket programming in C #

0


a source







All Articles