Solved

VB.Net Socket not Blocking

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

863 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

27 Experts available now in Live!

Get 1:1 Help Now