Results 1 to 3 of 3

Thread: Socket Error

  1. #1

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Socket Error

    "The requested address is not valid in its context."

    Code:
    Try
        Dim ipAddress As IPAddress = IPAddress.Parse("192.168.0.4")
        Dim localEndPoint As New IPEndPoint(ipAddress, 1420)
     
        mySocket = New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)
     
        mySocket.Bind(localEndPoint)
     
        Dim szData As String = vbCr & vbLf
        Dim byData As Byte() = System.Text.Encoding.ASCII.GetBytes(szData)
      
        Dim sender1 As New IPEndPoint(IPAddress.Any, 0)
        Dim tmpRemote As EndPoint = DirectCast((sender1), EndPoint)
     
        mySocket.SendTo(byData, tmpRemote)
     
        recv = mySocket.ReceiveFrom(data, tmpRemote)
        TerminalTextBox.Text += "Message received from: " & tmpRemote.ToString()
        TerminalTextBox.Text += Encoding.ASCII.GetString(data, 0, recv)
     
        While True
            data = New Byte(1023) {}
            recv = mySocket.ReceiveFrom(data, tmpRemote)
            Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv))
     
        End While
    
    Catch se As SocketException
        MessageBox.Show(se.Message)
    End Try

    Any ideas?

  2. #2

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Socket Error

    Is the UdpClient class better to use?

  3. #3
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Socket Error

    I get the same problem with my chat program if I don't type in my own IP or 127.0.0.1. Does anyone know??

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width