Solved

VB.Net Socket not Blocking

Posted on 2013-06-05
4
212 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

751 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