Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old May 21st, 2007, 1:16 PM   #1
surf3rb0y
Newbie
 
Join Date: Dec 2006
Posts: 8
Rep Power: 0 surf3rb0y is on a distinguished road
Asynchronous Network communication

I am trying to open 2 tcp connections to a server both asynchronous connections. My problem is when i setup the async call back only one of them works and the other gives me an error. Is there an easy way to setup two async call backs that do not conflict with one another.

Surferboy


Private Sub CommandRecieveCallBack(ByVal arone As IAsyncResult)
        Try
            If CommandSocket.Connected = True Then
                Dim bytes() As Byte = CType(arone.AsyncState, Byte())
                Dim numbytes As Int32 = CommandSocket.EndReceive(arone)
                If numbytes = 0 Then
                    CommandSocket.Shutdown(SocketShutdown.Both)
                    CommandSocket.Close()

                    Dim dlgone As New NoParamsDelegate(AddressOf DisConnectedUI)
                    Me.Invoke(dlgone)
                Else
                    Dim Recv As String = ASCII.GetString(bytes, 0, numbytes)
                    ' clear the array

                    Array.Clear(bytes, 0, bytes.Length)
                    ' show changes in UI
                    Dim dlgone As New OneStringDelegate(AddressOf DisplayRecieveData)
                    Dim args() As Object = {Recv}
                    Me.Invoke(dlgone, args)
                    ' Begin Recieving again
                    CommandSocket.BeginReceive(bytes, 0, bytes.Length, SocketFlags.None, AddressOf CommandRecieveCallBack, bytes)
                End If
            End If

        Catch ex As Exception

            System.Console.WriteLine("Disconnected")

        End Try


    End Sub

Private Sub CommandConnectCallBack(ByVal arone As IAsyncResult)
        Try
            CommandSocket.EndConnect(arone)
            'SendCommandData()
            Dim dlgone As New NoParamsDelegate(AddressOf ConnectedUI)
            Me.Invoke(dlgone)
            ' begin recieve
            ' create buffer
            Dim bytes(17000) As Byte
            CommandSocket.BeginReceive(bytes, 0, bytes.Length, SocketFlags.None, AddressOf CommandRecieveCallBack, bytes)
        Catch ex As SocketException
            MessageBox.Show("The Server was either down or not responding.  Please double check your server information that is under EtherNet->Configure.")
            Console.WriteLine("Failed in ConnectCallBack")
        End Try

    End Sub
surf3rb0y is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
network monitoring program fresher Java 7 Jan 16th, 2007 8:58 AM
VB6 Network Game - Server List His_Ryanness Visual Basic 0 Jun 14th, 2006 4:54 PM
network gaming Nebula Coder's Corner Lounge 2 Jun 11th, 2006 2:31 AM
Please Please Read - Very Big Bad Network Problems bigguy Coder's Corner Lounge 9 Feb 16th, 2006 8:46 PM
Help with asynchronous sockets? Brent C++ 3 Sep 9th, 2005 3:13 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:36 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC