Regarding Callback method used for BeginReceive method
Regarding Callback method used for BeginReceive method
Regarding Callback method used for BeginReceive method
Regarding Callback method used for BeginReceive method
Regarding Callback method used for BeginReceive method
Regarding Callback method used for BeginReceive method Regarding Callback method used for BeginReceive method Regarding Callback method used for BeginReceive method Regarding Callback method used for BeginReceive method Regarding Callback method used for BeginReceive method Regarding Callback method used for BeginReceive method Regarding Callback method used for BeginReceive method Regarding Callback method used for BeginReceive method
Regarding Callback method used for BeginReceive method Regarding Callback method used for BeginReceive method
Regarding Callback method used for BeginReceive method
Go Back  Xtreme Visual Basic Talk > > > Regarding Callback method used for BeginReceive method


Reply
 
Thread Tools Display Modes
  #1  
Old 08-03-2012, 06:44 AM
sattu sattu is offline
Newcomer
 
Join Date: Jun 2011
Posts: 7
Question Regarding Callback method used for BeginReceive method


Hi everyone,

Following is the callback method that I use in my socket programming at client side for async receiving of data from server:-

Code:
Public Sub Connect()
m_clientSocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
m_clientSocket.Connect(Ip, PortNo)
If (m_clientSocket.Connected) Then
       m_clientSocket.BeginReceive(dataBuffer, 0,dataBuffer.Length SocketFlags.None, New AsyncCallback(AddressOf OnDataReceived), m_clientSocket)     //here I connect the callback OnDataRecieved
End If
End Sub

Public Sub OnDataRecieved(ByVal async As IAsyncResult)
        Dim Recieved_Size As Integer = m_clientSocket.EndReceive(async)
        ...........(rest of the code)
End Sub
What my doubt is that when inside "OnDataRecieved method" "Recieved_Size" = 0, should I conclude that the socket has got disconnected? If not, then under what cases should Recieved_Size be = 0 ?

Why I am asking is that whenever the connected server gets disconnected then "OnDataRecieved" method gets called and the resulting "Recieved_Size" is = 0. But it should be called only when there is some data to be read for the socket, not when connect/disconnect happens, right?


I would really appreciate anyone who would clarify my doubt. Thanks in advance.
Reply With Quote
  #2  
Old 08-09-2012, 12:48 PM
RealityRipple's Avatar
RealityRipple RealityRipple is offline
Contributor
 
Join Date: Apr 2004
Location: Nipomo, California
Posts: 456
Default

If a receive event occurs and 0 bytes have been transferred, it means the connection has been dropped by the remote server.
Reply With Quote
  #3  
Old 08-09-2012, 11:16 PM
sattu sattu is offline
Newcomer
 
Join Date: Jun 2011
Posts: 7
Default

Hey Thanks,

I had implemented this logic in my code assuming that if I receive 0 bytes, that means remote host got disconnected. Your reply confirmed that.

Thanks once again
Reply With Quote
Reply


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 Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Regarding Callback method used for BeginReceive method
Regarding Callback method used for BeginReceive method
Regarding Callback method used for BeginReceive method Regarding Callback method used for BeginReceive method
Regarding Callback method used for BeginReceive method
Regarding Callback method used for BeginReceive method
Regarding Callback method used for BeginReceive method Regarding Callback method used for BeginReceive method Regarding Callback method used for BeginReceive method Regarding Callback method used for BeginReceive method Regarding Callback method used for BeginReceive method Regarding Callback method used for BeginReceive method Regarding Callback method used for BeginReceive method
Regarding Callback method used for BeginReceive method
Regarding Callback method used for BeginReceive method
 
Regarding Callback method used for BeginReceive method
Regarding Callback method used for BeginReceive method
 
-->