tags:

views:

120

answers:

1

Guys I need some help here.. I am doing a project in c# where the data needs to be sent as a datagram and receive data too which is broadcast.

The following 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 please tell me if the code is fine because there is no one around with whom i can test the code on lan Thanks a ton guys.

A: 

Why don't you set up your own broadcaster and listener in separate instances.

This is a great article on socket programming in c#

John Nolan