Networkstream Class and POP3 Protocol Problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Darcy Ryan

    Networkstream Class and POP3 Protocol Problem

    Greetings,

    I am having a problem trying to use the TcpClient and
    NetworkStream classes to connect to a POP3 server. My
    (simplified test) VB.NET code is as follows:

    Dim tcpclient As New TcpClient
    tcpclient.Conne ct("<server name>", 110)

    Dim ns As NetworkStream = tcpclient.GetSt ream

    Dim Rxbytes(tcpclie nt.ReceiveBuffe rSize) As Byte
    ns.Read(Rxbytes , 0, CInt(tcpclient. ReceiveBufferSi ze))

    Dim Txbytes As Byte() = Encoding.ASCII. GetBytes("USER
    <name>\r\n")

    ns.Write(Txbyte s, 0, Txbytes.Length)

    ns.Read(Rxbytes , 0, CInt(tcpclient. ReceiveBufferSi ze))

    ...

    The code above will connect to the POP3 server and read
    the "+OK ..." response for an active connection. The write
    command executes ok, but the program hangs on the Read
    command (as if the server has not recieved a valid USER
    command). I have added a check for ns.DataAvailabl e prior
    to the read, which returns no data available. I think that
    I am missing something obvious in writing the USER command
    (possibly with the CRLF).

    I have verified my command strings by connecting to my
    server using telnet, I have checked the samples on MSDN
    and Google, and I am now into the 'banging head on
    keyboard' stage.

    Any advice?

    Thanks,
    Darcy
  • A

    #2
    Re: Networkstream Class and POP3 Protocol Problem

    > I have verified my command strings by connecting to my[color=blue]
    > server using telnet, I have checked the samples on MSDN
    > and Google, and I am now into the 'banging head on
    > keyboard' stage.
    >
    > Any advice?[/color]

    Perhaps you need to send a NULL terminated string? "\0" I know that
    sometimes that is what is expected. Just a guess.

    -akshay


    Comment

    • Darcy Ryan

      #3
      Re: Networkstream Class and POP3 Protocol Problem

      I tried that both after and in place of the CRLF (\r\n)
      characters (spec'd by the POP3 protocol) with no luck.
      Thanks for the suggestion though, Akshay, I hadn't thought
      of that.

      Darcy
      [color=blue]
      >
      >Perhaps you need to send a NULL terminated string? "\0" I[/color]
      know that[color=blue]
      >sometimes that is what is expected. Just a guess.
      >
      >-akshay
      >
      >
      >.
      >[/color]

      Comment

      • Stephen Martin

        #4
        Re: Networkstream Class and POP3 Protocol Problem

        VB does not use escape sequences such as '\r\n'. Try:

        Dim Txbytes As Byte() = Encoding.ASCII. GetBytes("USER <name>" &
        Environment.New Line)

        "Darcy Ryan" <darcyryan@hotm ail.com> wrote in message
        news:005c01c34d 54$c39db4b0$a50 1280a@phx.gbl.. .[color=blue]
        > Greetings,
        >
        > I am having a problem trying to use the TcpClient and
        > NetworkStream classes to connect to a POP3 server. My
        > (simplified test) VB.NET code is as follows:
        >
        > Dim tcpclient As New TcpClient
        > tcpclient.Conne ct("<server name>", 110)
        >
        > Dim ns As NetworkStream = tcpclient.GetSt ream
        >
        > Dim Rxbytes(tcpclie nt.ReceiveBuffe rSize) As Byte
        > ns.Read(Rxbytes , 0, CInt(tcpclient. ReceiveBufferSi ze))
        >
        > Dim Txbytes As Byte() = Encoding.ASCII. GetBytes("USER
        > <name>\r\n")
        >
        > ns.Write(Txbyte s, 0, Txbytes.Length)
        >
        > ns.Read(Rxbytes , 0, CInt(tcpclient. ReceiveBufferSi ze))
        >
        > ...
        >
        > The code above will connect to the POP3 server and read
        > the "+OK ..." response for an active connection. The write
        > command executes ok, but the program hangs on the Read
        > command (as if the server has not recieved a valid USER
        > command). I have added a check for ns.DataAvailabl e prior
        > to the read, which returns no data available. I think that
        > I am missing something obvious in writing the USER command
        > (possibly with the CRLF).
        >
        > I have verified my command strings by connecting to my
        > server using telnet, I have checked the samples on MSDN
        > and Google, and I am now into the 'banging head on
        > keyboard' stage.
        >
        > Any advice?
        >
        > Thanks,
        > Darcy[/color]


        Comment

        Working...