![]() |
Click here to advertise with us
|
|
|||||||
| Net / Sockets Components for network and related use |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
||||
|
Hello people.
A while ago I've started to write my own network layer based upon the TCPClient and the NetworkStream. I'm using a while loop to receive data: Code:
Dim buffer(Me.prv_client.ReceiveBufferSize - 1) As Byte
Dim read As Integer = Int32.MaxValue
Do
Try
read = Me.prv_strm.Read(buffer, 0, buffer.Length)
Catch ex As IOException
Me.writeError(ex.Message)
read = 0
End Try
'Do something with it
Loop While Me.prv_strm.DataAvailable
If I know the size of the received data, there's no problem 'cause I read until I have everything. But what I don't have that information? Of course, using Threading.Thread.Sleep() seems to be a solution, but that one feels just plain wrong. Anyone some ideas on that? Bobby
__________________
Don't give TypeCasting Errors a chance, turn ON Option Strict! Greatest Obfuscator ever: EazFuscator (Freeware) Greatest Reflection Tool ever: .NET Reflector (Freeware) with Add-Ins Greatest Introspection Tool ever: Gendarme (GPL) Greatest MySQL FrontEnd ever: MySQL-Front (Shareware), HeidiSQL (GPL) |
|
||||
|
What is it you're reading, and why don't you know the size?
If the reading is indefinite and you're just reading from the open stream you can do-loop on some other condition, f.ex until app or stream close or message known to be ended, and only read if data is available.
__________________
Some useful links: Learning videoes, Code Samples, WMI Code Creator, MSDN, The Code Project, WindowsClient.net, ASP.net, W3 Schools, Regular-Expressions.info, GDI+ FAQ
How to format posts with code blocks etc - present the problem/post properly ![]() |
|
||||
|
I'm able to request the size for my purposes (f.e. FTP, POP3) but was wondering if it is really necessary.
I also tried other conditions, f.e. until the amount of read data is zero...but that does not only throw an exception, but does also kill my whole connection with the server. Which is not desirable if you're within a protocol session. Code:
Loop While read > 0 Thanks for replying and in advance, Bobby
__________________
Don't give TypeCasting Errors a chance, turn ON Option Strict! Greatest Obfuscator ever: EazFuscator (Freeware) Greatest Reflection Tool ever: .NET Reflector (Freeware) with Add-Ins Greatest Introspection Tool ever: Gendarme (GPL) Greatest MySQL FrontEnd ever: MySQL-Front (Shareware), HeidiSQL (GPL) |
|
|||
|
I have the same issue I'm actually seriallizing a structure on the server side then sending that to the client ... I ended up just putting the .sleep(10) in there and in my network that seems to do the trick ... but your right that does seem totally wrong ... I can't think of a better way. .. if you come up with one I would love to hear it
|
|
||||
|
Hello anthony.
No I didn't come up with a better solution then this by now. Though, I've got some basic ideas how to bypass this...but none seems to be a really good idea to me. One was to build somekind of Timout-Loop into the function: Code:
Dim buffer(Me.prv_client.ReceiveBufferSize - 1) As Byte
Dim read As Integer = Int32.MaxValue
Dim timeOut As Integer = 0
Do
Try
read = Me.prv_strm.Read(buffer, 0, buffer.Length)
Catch ex As IOException
read = 0
End Try
'Do something with it
While timeOut < 256 And Not Me.prv.strm.DataAvailable
timeout += 1
End While
timeOut = 0
Loop While Me.prv_strm.DataAvailable
But you brought me on the idea to have a look at these classes in the Reflector...maybe I can find a solution down there. Though, I ask myself if the same issue exists within Mono, I'll try that one out tomorrow. Bobby
__________________
Don't give TypeCasting Errors a chance, turn ON Option Strict! Greatest Obfuscator ever: EazFuscator (Freeware) Greatest Reflection Tool ever: .NET Reflector (Freeware) with Add-Ins Greatest Introspection Tool ever: Gendarme (GPL) Greatest MySQL FrontEnd ever: MySQL-Front (Shareware), HeidiSQL (GPL) |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|