Solved

VB.Net Socket not Blocking

Posted on 2013-06-05
4
200 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

747 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now