socket.receive fails to receive 
Author Message
 socket.receive fails to receive

      I'm working on building a pop3 server.  USER, PASS, and STAT are
received from the client.  However, after the first 3 commands come through,
the pop server hangs.  From my logging I have been able to determine that
the problem lies in the following code:

      Dim byteArray(2048) As Byte

      Try
          logger.writeLog("Entering try loop...")
          logger.writeLog("Receiving data from client...")
          ' problem is this next line
          Dim numBytes As Integer = serverSockForClient.Receive(byteArray,
byteArray.Length, 0)
          logger.writeLog("Encoding data in ASCII format...")
          Dim clientMessage As String = Encoding.ASCII.GetString(byteArray)
          logger.writeLog("Truncating clientMessage...")
          clientMessage = truncateCommand(clientMessage)
          logger.writeLog("Message received: " & clientMessage)

          If numBytes > 0 Then
              pop3command = parseCommand(clientMessage, pop3lastCommand,
pop3userName)
          Else
              pop3command = POP3_QUIT
          End If

          noExitFlag = handlePopCommand(pop3command, clientMessage,
serverSockForClient, pop3userName)
          logger.writeLog("noExitFlag: " & noExitFlag)
          Catch except As NotSupportedException
              logger.writeLog(except.ToString)
          Catch except As SocketException
              logger.writeLog(except.ToString)
          End Try

      Normally, the message is read into the byteArray and then truncated.
However, it appears that something is not processing correctly.

      Any help in appreciated.

      Thanks in advance,

      Jeremiah



Sat, 30 Jul 2005 21:09:28 GMT  
 socket.receive fails to receive
That's because you're telling the buffer what size it should be instead of
finding out what the the length of the buffer is:

Your code:

Dim numBytes As Integer = serverSockForClient.Receive(byteArray,
byteArray.Length, 0)

Suggested fix:

Dim ClientStream as system.io.streamreader =. new system.io.streamreader
(serverSocketForClient.GetStream())

hth


Quote:
>       I'm working on building a pop3 server.  USER, PASS, and STAT are
> received from the client.  However, after the first 3 commands come
through,
> the pop server hangs.  From my logging I have been able to determine that
> the problem lies in the following code:

>       Dim byteArray(2048) As Byte

>       Try
>           logger.writeLog("Entering try loop...")
>           logger.writeLog("Receiving data from client...")
>           ' problem is this next line
>           Dim numBytes As Integer = serverSockForClient.Receive(byteArray,
> byteArray.Length, 0)
>           logger.writeLog("Encoding data in ASCII format...")
>           Dim clientMessage As String =

Encoding.ASCII.GetString(byteArray)

- Show quoted text -

Quote:
>           logger.writeLog("Truncating clientMessage...")
>           clientMessage = truncateCommand(clientMessage)
>           logger.writeLog("Message received: " & clientMessage)

>           If numBytes > 0 Then
>               pop3command = parseCommand(clientMessage, pop3lastCommand,
> pop3userName)
>           Else
>               pop3command = POP3_QUIT
>           End If

>           noExitFlag = handlePopCommand(pop3command, clientMessage,
> serverSockForClient, pop3userName)
>           logger.writeLog("noExitFlag: " & noExitFlag)
>           Catch except As NotSupportedException
>               logger.writeLog(except.ToString)
>           Catch except As SocketException
>               logger.writeLog(except.ToString)
>           End Try

>       Normally, the message is read into the byteArray and then truncated.
> However, it appears that something is not processing correctly.

>       Any help in appreciated.

>       Thanks in advance,

>       Jeremiah



Sat, 30 Jul 2005 22:39:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Receiving notification on Send, Receive and Delete

2. Synchronism between a send and a receive (socket ftp)

3. is net.socket able to block receiving data until it handles the data

4. Socket Receive - Force to wait for complete stream??

5. SOCKET : Receiving and sending in different threads

6. Async UDP Receive and Send from the same socket

7. Receiving data using a Socket

8. Receive data through UDP-Socket.....?

9. Socket.Receive method hangs

10. socket.receive [VB .NET]

11. Receiving data from socket

12. Winsock DataArrival, socket closing and can't GetData before receiving all the data

 

 
Powered by phpBB® Forum Software