Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB.Net Socket not Blocking

Posted on 2013-06-05
4
Medium Priority
?
225 Views
Last Modified: 2013-06-16
Hi,

I've written some code which is supposed to block when socket.receive is called, however it doesnt block when no data is available.

    Public Function ReadLine() As String
        Dim IncomingData() As Byte = New Byte(4095) {}
        Dim IncomingString As String

        Dim ResultString As String
        Dim ByteCount As Integer

        tcpConnection.Blocking = True

        If InStr(InputBuffer, vbCrLf) > 0 Then
            ResultString = InputBuffer.Substring(0, InputBuffer.IndexOf(vbCrLf))
            InputBuffer = InputBuffer.Substring(InputBuffer.IndexOf(vbCrLf) + 2)
            Return ResultString
        End If

        ByteCount = tcpConnection.Receive(IncomingData)

        ReDim Preserve IncomingData(ByteCount - 1)
        IncomingString = Encoding.ASCII.GetString(IncomingData)

        InputBuffer = InputBuffer & IncomingString

        If InStr(InputBuffer, vbCrLf) > 0 Then
            ResultString = InputBuffer.Substring(0, InputBuffer.IndexOf(vbCrLf))
            InputBuffer = InputBuffer.Substring(InputBuffer.IndexOf(vbCrLf) + 2)
            Return ResultString
        Else
            Return Nothing
        End If

    End Function

Open in new window


Any idea why its not blocking?
Thanks
Dan
0
Comment
Question by:DanJourno
  • 2
4 Comments
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
ID: 39225079
Hi,

Sorry for asking, but, what do you mean by "block"?

Giannis
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39239543
Have you stepped through the code to see if it is reaching line 16?
0
 
LVL 5

Accepted Solution

by:
DanJourno earned 0 total points
ID: 39239567
Found the solution. If the remote party closes the connection, Receive doesn't block.
0
 
LVL 5

Author Closing Comment

by:DanJourno
ID: 39251078
Found the solution myself.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Integration Management Part 2
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question