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

#1 Arkwind  Icon 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
        myListener.Start()

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




DoAcceptTcpClientCallBack


    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

        Try
            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



Timer:

    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  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3248
  • View blog
  • Posts: 10,894
  • 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