title: VB.net TCP Non-Blocking State
body: <p>I have code that sending string from client to server with TCP Connection.
  But i dont know how to convert it to NonBlocking TCP State Connection.
  i have try to put socket.Blocking = FALSE, but that code give me an error.</p>
  
  <p>Socket Error Code: 10035</p>
  
  <p>Exception Title: A non-blocking socket operation could not be completed immediately</p>
  
  <p>Heres my code for sending string from client to server.</p>
  
  <p>Server Code :</p>
  
  <pre><code>Imports System.Net
  Imports System.Net.Sockets
  Imports System.Text
  
  Module Module1
      Dim soket As Socket
      Sub Main()
          Try
              Dim alamatIP As IPAddress = IPAddress.Parse("127.0.0.1")
              Dim tcpListener As New TcpListener(alamatIP, 8000)
              'soket.Blocking = False - THIS WILL GIVE ME AN ERROR
              tcpListener.Start()
  
              System.Console.WriteLine("Server port 8000...")
  
              Dim myendpoint As IPEndPoint
              myendpoint = CType(tcpListener.LocalEndpoint, IPEndPoint)
  
              System.Console.WriteLine("IP : " + myendpoint.Address.ToString + " and port is " + myendpoint.Port.ToString)
              System.Console.WriteLine("Waiting for connection !")
  
              soket = tcpListener.AcceptSocket()
              myendpoint = CType(soket.RemoteEndPoint(), IPEndPoint)
  
              System.Console.WriteLine("Receiving from " + myendpoint.Address.ToString())
  
              Dim bitData(100) As Byte
              Dim newString As String = ""
              Do
                  Try
                      Dim size As Integer = soket.Receive(bitData)
                      newString = Encoding.ASCII.GetString(bitData)
                      Console.WriteLine(newString)
                      Array.Clear(bitData, 0, bitData.Length)
                  Catch ex As Exception
                      Console.Write(ex.ToString())
                  End Try
              Loop While newString &lt;&gt; "exit"
              soket.Close()
              tcpListener.Stop()
          Catch ex As Exception
              Console.WriteLine("Error ..." + ex.ToString())
          End Try
          Console.ReadLine()
      End Sub
  
  End Module
  </code></pre>
  
  <p>Client Code : </p>
  
  <pre><code>Imports System.Net
  Imports System.Net.Sockets
  Imports System.Text
  Imports System.IO
  Imports System.Threading
  Module Module1
  
      Sub Main()
          Try
              Dim tcpClient As New TcpClient 'creating the client
              Console.WriteLine("Connecting....")
              tcpClient.Connect("127.0.0.1", 8000) 'connecting the client the server
              'port is same as in the server
              Console.WriteLine("Connected")
              Console.WriteLine("Enter the string to be transmitted : ")
  
              Dim strMessage As String
              Dim stm As Stream
              Dim counter As Integer = 0
  
              Do
  
                  stm = tcpClient.GetStream() 'getting the stream of the client
                  Dim ascenc As New ASCIIEncoding
                  strMessage = Console.ReadLine()
                  Dim byteData() As Byte = ascenc.GetBytes(strMessage)
                  Console.WriteLine("Transmitted ")
                  stm.Write(byteData, 0, byteData.Length())
  
              Loop While strMessage &lt;&gt; "exit"
  
                      tcpClient.Close() 'closing the connection
          Catch ex As Exception
              Console.WriteLine("Error..." + ex.StackTrace.ToString()) 'writing the exception into the console
          End Try
      End Sub
  
  End Module
  </code></pre>
  
  <p>Thanks for any help.</p>