Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
C# - Code Freezes Up
Message
 
To
20/01/2008 00:25:53
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01283306
Message ID:
01283835
Views:
12
I made the change, and the code still freezes. I don't understand what's going on.
This is a really small piece of code.

Any chance you could take a look? The code is here
http://www.geocities.com/kevin.marois/xmail/xmail.zip

Signed, Desparatly Lost.







>It doesn't look like you did a straight copy/paste.
>
>In the codeproject code, NetStrm is declared like this:
>
>
>public NetworkStream NetStrm;
>...
>NetStrm = Server.GetStream();
>
>
>You've just declared it as a plain ol' Stream:
>
>
>Stream NetStrm = Server.GetStream();
>
>
>Makes a bit of a difference. <g>
>
>~~Bonnie
>
>
>
>>Thanks for the reply.
>>
>>Like I said, I got this code from http://www.codeproject.com/KB/IP/popapp.aspx
>>I went back & looked, and the sample code is doing the same thing.
>>
>>Secondly, I have not yet put in any exception handling.
>>
>>Finally, the stream will be terminated with a '.', which I will be testing for at a
>>later point.
>>
>>
>>I copied this from the example and pasted this at the top of Connect:
>>
>>TcpClient Server = new TcpClient(_sPOP3Server, 25);
>>Stream NetStrm = Server.GetStream();
>>StreamReader RdStrm = new StreamReader(Server.GetStream());
>>string s = RdStrm.ReadLine();
>>
>>
>>and it hangs on the ReadLine.
>>
>>I have the example code on my PC and it runs fine. When I put this into my class,
>>it hangs.
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>>>I'm writing a little C# app that connects to a POP3 mailbox and checks for mail.
>>>>The code freezes with a console window open at the indicated line.
>>>>
>>>>This is an adaption of the code found here http://www.codeproject.com/KB/IP/popapp.aspx
>>>>
>>>>Anyone know what's going on?
>>>>
>>>>
>>>>
>>>>/***************************************************************
>>>> * This is the test console app
>>>> ***************************************************************/
>>>>static void Main(string[] args)
>>>>{
>>>>    int i = 0;
>>>>
>>>>    XMail.XMail oMail = new XMail.XMail();
>>>>
>>>>    oMail.sPOP3Server = "incoming.verizon.net";
>>>>    oMail.iPort = 25;
>>>>
>>>>    oMail.Connect("myusername", "mypassword");
>>>>
>>>>}
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>/***************************************************************
>>>> * This is the class
>>>> ***************************************************************/
>>>>public class XMail
>>>>{
>>>>
>>>>    private string _sPOP3Server;
>>>>    private int _iPort;
>>>>    private TcpClient oServer = null;
>>>>    private Stream oStream = null;
>>>>    private StreamReader oReader = null;
>>>>
>>>>
>>>>    public bool Connect(string sLoginName, string sPassword)
>>>>    {
>>>>        bool bRetVal = false;
>>>>        string sResponse;
>>>>
>>>>        oServer = new TcpClient(_sPOP3Server, _iPort);
>>>>
>>>>        oStream = oServer.GetStream();
>>>>
>>>>        oReader = new StreamReader(oServer.GetStream());
>>>>
>>>>        sResponse = oReader.ReadLine();       <== FREEZES ON THIS LINE
>>>>
>>>>        // More code to follow here:
>>>>
>>>>        return bRetVal;
>>>>    }
>>>>
>>>>}
>>>>
>>>
>>>
>>>Acouple of things jump out right away, not sure if they could cause your problem or not...
>>>
>>>There is no error checking for the return values for oServer, oStream and oReader. Are you sure they're being initialized correctly?
>>>
>>>Secondly, you fill oStream by making a call to oServer.GetStream(), then you make the same call in the oReader line never using the oStream object. Could it be that oStream holds the stream and not the subsequent call to oServer.GetStream()?
>>>
>>>Thirdly, Stream readers are usually placed in some kind of loop to test for the end of file or the presence of more characters:
>>>
>>>
>>>
>>>using (StreamReader sr = new StreamReader(oStream))
>>>{
>>>   while (sr.Peek() >= 0)
>>>   {
>>>      sResponse = sr.ReadLine());
>>>      if (! string.IsNullOrEmpty(sResponse))
>>>      {
>>>          do ssomething here....
>>>      }
>>>   }
>>>}
>>>
>>>
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform