Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Background Workers with Asynch TCP Connections [modified]

Background Workers with Asynch TCP Connections [modified]

Scheduled Pinned Locked Moved Visual Basic
helpcsharpdesignquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chinners
    wrote on last edited by
    #1

    Hi, I am trying to use remoting for an application I am writing. One problem with remoting is the timeout is too high if a particular IP address is not found (i.e. the remote machine is not turned on). I also need to check that the remote listener is alive. My solution to this was to write a small routine that "Pings" the remote object beforehand to see if it was alive. This "Ping" routine uses a s simple async TCP connection, so I can adjust the timeout: Private HasResponded As Boolean Private Timeout As Integer = 100 Private Sub TCPResponded(ByVal ar As System.IAsyncResult) HasResponded = True End Sub Public Function IsAlive(ByVal IPAddress As String) As Boolean Dim Conn As New AsyncCallback(AddressOf TCPResponded) Dim Tcp As New System.Net.Sockets.TcpClient() Dim MyTimeOut As Integer = Timeout HasResponded = False Tcp.BeginConnect(IPAddress, 9000, Conn, Nothing) While HasResponded = False And MyTimeOut > 0 System.Threading.Thread.Sleep(10) MyTimeOut -= 1 End While If Tcp.Connected Then Tcp.Close() Return True Else Tcp.Close() Return False End If End Function This class works fine when in the UI thread - it can tell me if a machine is alive or not within a second (I am only dealing with local ethernet, so one second is considered slow). However, in my UI, I would like an icon to display the status of the remote machine. I thought I could write a simple background worker to call the above code. However, on the TCP.BeginConnect, I get the following error: System.Net.Sockets.SocketException was unhandled by user code ErrorCode=10045 Message="The attempted operation is not supported for the type of object referenced" Source="System" StackTrace: at System.Net.Sockets.Socket.DoMultipleAddressConnectCallback(Object result, MultipleAddressConnectAsyncResult context) at System.Net.Sockets.Socket.BeginConnect(String host, Int32 port, AsyncCallback requestCallback, Object state) at System.Net.Sockets.TcpClient.BeginConnect(String host, Int32 port, AsyncCallback requestCallback, Object state) Has anyone tried an Async connect within a background worker before, and got it working? I have tried googling this, but cant find anything that looks vaguely similar to my problem. As of yesterday, I h

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups