1 Replies - 2458 Views - Last Post: 30 August 2013 - 06:06 AM Rate Topic: -----

#1 Arkwind   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 28-November 08

Non Blocking TCP Server with Timers

Posted 30 August 2013 - 04:31 AM

Hi All,

I have a TCP listener configured that should be asynchronous, I also have a timer set up, but when the socket is listening the timer.tick event doesn't fire. Can someone tell me why this code isnt asynchronous.

        Public Shared allDone As New ManualResetEvent(False)

In my form load section:
        'Create an aysync tcp listener
        Dim myListener As New TcpListener(IPAddress.Parse(GetIPv4Address()), 50000)

        'Start the listener

        'Shouldnt block
        While True
            'Handles threading
            'On client connect
            myListener.BeginAcceptTcpClient(New AsyncCallback(AddressOf DoAcceptTcpClientCallback), myListener)
        End While


    Public Sub DoAcceptTcpClientCallback(ByVal ar As IAsyncResult)

        'Triggered On A Client Connect
        Dim listener As TcpListener = CType(ar.AsyncState, TcpListener)
        Dim client As TcpClient = Nothing

            client = listener.EndAcceptTcpClient(ar)
        Catch ex As Exception
            client = Nothing
        End Try

        Dim ns As NetworkStream = client.GetStream
        Dim sr As New StreamReader(ns)

        ..do work...
        listener.BeginAcceptTcpClient(New AsyncCallback(AddressOf DoAcceptTcpClientCallback), listener)

    End Sub


    Private Sub TwoSecondTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TwoSecondTimer.Tick
 MsgBox("This should appear but doesnt")
End Sub

Where am I going wrong?

Is This A Good Question/Topic? 0
  • +

Replies To: Non Blocking TCP Server with Timers

#2 andrewsw   User is offline

  • RequestedRangeNotSatisfiable
  • member icon

Reputation: 6552
  • View blog
  • Posts: 26,566
  • Joined: 12-December 12

Re: Non Blocking TCP Server with Timers

Posted 30 August 2013 - 06:06 AM

If the Tick event doesn't run then have you started the Timer and given it an interval?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1