You will have to excuse me because I am very new to programming. I am trying to modify Micorosofts example code for a TcpListener. If I leave it alone at address "127.0.0.1" it works just like it is suppose to. But if i change the address to lets say "10.1.1.1" It no longer works. It throws up an Exception: Requested Address is not valid within its context. Here's the code if you want to know what I am changing.

Any Ideas or corrections are greatly welcome.

Thanks
gunslngr


VB Code:
  1. Imports System
  2. Imports System.IO
  3. Imports System.Net
  4. Imports System.Net.Sockets
  5. Imports System.Text
  6. Imports Microsoft.VisualBasic
  7. Imports System.Configuration
  8.  
  9.  
  10. Class MyTcpListener
  11.  
  12.     Public Shared Sub Main()
  13.  
  14.         Try
  15.             ' Set the TcpListener on port 13000.
  16.             Dim port As Int32 = 13000
  17.             Dim localAddr As IPAddress = IPAddress.Parse("10.1.1.1")
  18.  
  19.             Dim server As New TcpListener(localAddr, port)
  20.  
  21.             ' Start listening for client requests.
  22.             server.Start()
  23.  
  24.             ' Buffer for reading data
  25.             Dim bytes(1024) As [Byte]
  26.             Dim data As [String] = Nothing
  27.  
  28.             ' Enter the listening loop.
  29.             While True
  30.                 Console.Write("Waiting for a connection... ")
  31.  
  32.                 ' Perform a blocking call to accept requests.
  33.                 ' You could also user server.AcceptSocket() here.
  34.                 Dim client As TcpClient = server.AcceptTcpClient()
  35.                 Console.WriteLine("Connected!")
  36.  
  37.                 data = Nothing
  38.  
  39.                 ' Get a stream object for reading and writing
  40.                 Dim stream As NetworkStream = client.GetStream()
  41.  
  42.                 Dim i As Int32
  43.  
  44.                 ' Loop to receive all the data sent by the client.
  45.                 i = stream.Read(bytes, 0, bytes.Length)
  46.                 While (i <> 0)
  47.                     ' Translate data bytes to a ASCII string.
  48.                     data = System.Text.Encoding.ASCII.GetString(bytes, 0, i)
  49.                     Console.WriteLine([String].Format("Received: {0}", data))
  50.  
  51.                     ' Process the data sent by the client.
  52.                     data = data.ToUpper()
  53.  
  54.                     Dim msg As [Byte]() = System.Text.Encoding.ASCII.GetBytes(data)
  55.  
  56.                     ' Send back a response.
  57.                     stream.Write(msg, 0, msg.Length)
  58.                     Console.WriteLine([String].Format("Sent: {0}", data))
  59.  
  60.                     i = stream.Read(bytes, 0, bytes.Length)
  61.  
  62.                 End While
  63.  
  64.                 ' Shutdown and end connection
  65.                 client.Close()
  66.             End While
  67.         Catch e As SocketException
  68.             Console.WriteLine("SocketException: {0}", e)
  69.         End Try
  70.  
  71.         Console.WriteLine(ControlChars.Cr + "Hit enter to continue...")
  72.         Console.Read()
  73.     End Sub 'Main
  74.  
  75. End Class 'MyTcpListener