Visual Basic .NET Forums  
Click here to advertise with us

Go Back   Visual Basic .NET Forums > Components & Controls > Net / Sockets

Net / Sockets Components for network and related use

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-09-2009, 12:01 PM
Robert_Zenz's Avatar
VB.NET Forum Idol
.NET Framework: .NET 2.0
 
Join Date: Jun 2008
Location: Vienna, Austria
Age: 22
Posts: 503
Reputation: 290
Robert_Zenz master of VB.NETRobert_Zenz master of VB.NETRobert_Zenz master of VB.NETRobert_Zenz master of VB.NETRobert_Zenz master of VB.NETRobert_Zenz master of VB.NETRobert_Zenz master of VB.NETRobert_Zenz master of VB.NETRobert_Zenz master of VB.NET
Default Server counts LF but delivers CrLf?

Hello everyone again.

I was writing my own POP3 client but ran into some problems along the way. I could hunt down one of them by now, which seems to be the key to most of the problems I experienced.

I'm using a TCPClient to connect to the server and a NetworkStream to read and write data. This is working great, except one thing: The LIST command delivers me the size of the mail in bytes...but with Lf counted, though, if I start to download the mail with the RETR command, I receive CrLf?!

I'm using the simple NetworkStream.Read(bytes(), offset, length) Method to read from the network. This method already delivers CrLf...but the server counts Lf and so the size I received is totally messed up.

Code:
'toReceive is an Int32 from the LIST command
'Me.prv_client is the TCPClient
'Me.prv_strm is the NetworkStream from the client

            Dim buffer(Me.prv_client.ReceiveBufferSize - 1) As Byte
            Dim readAll As Integer = 0
            Dim read As Integer = Int32.MaxValue

            Do
                Array.Clear(buffer, 0, buffer.Length)
                read = 0

                Try
                    read = Me.prv_strm.Read(buffer, 0, buffer.Length)
                Catch ex As IOException
                    Me.writeError(ex.Message)
                End Try

                readAll += read

                res.Append(Me.prv_encoding.GetString(buffer, 0, read))
            Loop While readAll < toReceive
Of course, I'd count the Lf along the way and add them to toReceive (which I do right now, working), but that can't be the solution.

Anybody has ever seen something like this?

Thanks 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)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-09-2009, 2:36 PM
JohnH's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Dec 2005
Location: Norway
Age: 37
Posts: 10,322
Reputation: 1315
JohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond repute
Default

Why not use a StreamReader and StreamWriter with the NetworkStream? You are reading and sending crlf terminated lines of strings all the way with this protocol, ie ReadLine/WriteLine. Multiline responses simply end with a "." line.
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-10-2009, 3:44 AM
Robert_Zenz's Avatar
VB.NET Forum Idol
.NET Framework: .NET 2.0
 
Join Date: Jun 2008
Location: Vienna, Austria
Age: 22
Posts: 503
Reputation: 290
Robert_Zenz master of VB.NETRobert_Zenz master of VB.NETRobert_Zenz master of VB.NETRobert_Zenz master of VB.NETRobert_Zenz master of VB.NETRobert_Zenz master of VB.NETRobert_Zenz master of VB.NETRobert_Zenz master of VB.NETRobert_Zenz master of VB.NET
Default

Mmmhhh...you're right. I was afraid that there might be false positive with this simple char sequence (CrLf.CrLf), but they must be the last thing I read.

Thanks for your suggestion, I tried it and it's working (of course).

Thank you,
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)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 6:17 AM.

Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2


For advertising opportunities click here.