0
   Public udpReceivingClient As UdpClient   
   udpReceivingClient.BeginReceive(AddressOf MT_RX_Callback, Nothing) 

throws NullReferneceException.

How to use beginreceive method in UDP ? what mistake am I making ?

Matt Wilko
  • 25,893
  • 10
  • 85
  • 132
Sushant
  • 53
  • 7
  • possible duplicate of [What is a NullReferenceException and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Ňɏssa Pøngjǣrdenlarp Oct 13 '14 at 11:24

1 Answers1

0

Is this your complete code? You haven't assigned anything to the udpReceivingClient variable, hence it causes a Null Reference when you try to use it. Additionally, the UdpClient requires some information before you can use it, such as which port to listen to.

    Public udpReceivingClient As UdpClient = New UdpClient(port_number)

Turning on Option Explicit will help you avoid these errors.

Justin Ryan
  • 1,400
  • 1
  • 11
  • 25
  • Turning on Option Explicit will not help with a null reference exception – Matt Wilko Oct 13 '14 at 12:04
  • @MattWilko Yes, you're right. I'm not sure what I was thinking, except that "it's 5am and I've been up far too long." Option Explicit/Strict is a good idea anyway, and I find myself posting that link in many answers. – Justin Ryan Oct 13 '14 at 12:27