title: vb.net UDP broadcast show IP from sender
body: <p>I am sending a UDP broadcast out with the message "Hello?" using this code:</p>
  
  <pre><code>    Public Sub UDPSendHello()
  
      Dim client As New UDPClient()
      Dim ip As New IPEndPoint(IPAddress.Broadcast, 15000)
  
      Dim bytes As Byte() = Encoding.ASCII.GetBytes("Hello?")
      client.Send(bytes, bytes.Length, ip)
      client.Close()
  End Sub
  </code></pre>
  
  <p>Of couse I the UDPListner can recieve the message fine!</p>
  
  <pre><code>  Private ReadOnly udp As New UdpClient(15000)
      Public Sub UDPHelloListner()
          udp.BeginReceive(AddressOf Receive, New Object())
      End Sub
      Private Sub Receive(ByVal ar As IAsyncResult)
          Dim ip As New IPEndPoint(IPAddress.Any, 15000)
          Dim bytes As Byte() = udp.EndReceive(ar, ip)
          Dim message As String = Encoding.ASCII.GetString(bytes)
          If message = "Hello?" Then
              Dim sender As New IPEndPoint(IPAddress.Any, 15000)
              Dim senderRemote As EndPoint = CType(sender, EndPoint)
  
              MessageBox.Show("I see message, Hello")
          End If
  
          UDPHelloListner()
      End Sub
  </code></pre>
  
  <p>Well how can I get the senders IP address and show it in Messagebox,textbox,etc.</p>
  
  <p>I saw the <code>Socket.RecieveFrom</code> Method, but! I am getting this error <code>"The system detected an invalid pointer address in attempting to use a pointer argument in a call"</code> at this point of the below code, "   <code>s.ReceiveFrom(msg, SocketFlags.None, senderRemote)</code>"</p>
  
  <pre><code>   Public Sub ReceiveFrom2()
          Dim hostEntry As IPHostEntry = Dns.GetHostEntry(Dns.GetHostName())
          Dim endPoint As New IPEndPoint(hostEntry.AddressList(0), 11000)
  
          Dim s As New Socket(EndPoint.Address.AddressFamily, SocketType.Dgram, ProtocolType.Udp)
  
          ' Creates an IpEndPoint to capture the identity of the sending host. 
          Dim sender As New IPEndPoint(IPAddress.Any, 0)
          Dim senderRemote As EndPoint = CType(sender, EndPoint)
  
          ' Binding is required with ReceiveFrom calls.
          s.Bind(endPoint)
  
          Dim msg() As Byte = New [Byte](255) {}
          Console.WriteLine("Waiting to receive datagrams from client...")
          ' This call blocks. 
          s.ReceiveFrom(msg, SocketFlags.None, senderRemote)
          s.Close()
  
      End Sub 'ReceiveFrom2
  </code></pre>
  
  <p>So how would I get the sender IP and show it using the code above in a textbox,message,etc....????</p>