Solved

VB.Net Socket not Blocking

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

632 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