Click to See Complete Forum and Search --> : CSocket::OnReceive only called once


surferboy
December 22nd, 2004, 04:35 AM
I'm quite new to VC++/socket programming and have to make a client application based on CSocket that connects to a third-party server.

After Connect(), the client needs to handle a login procedure (in case of an error (wrong user name/password), by default the server doesn't send an error message):

(1) server sends a prompt for user name "User"<CR><LF>"."
(2) client sends user name "username"<CR><LF>"."
(3) server sends a prompt for password "Password"<CR><LF>"."
(4) client sends password "password"<CR><LF>"."

Currently, the process stops after (2). Send returns the correct number of bytes that were sent, and no error occurs, but I don't receive any further data from the server, which means OnReceive isn't triggered a second time.
So far I'm sending a character string (char* buffer) with '\r' for the carriage return, '\n' for the newline character and, as the server expects it, a terminating '\0'
For me, this arises the question if there's a code page problem that leads to a server-sided misinterpretation of the escape sequences or if there's something wrong with the OnReceive event that prevents it from being called a second time?
When I copy & paste the reply strings generated by my client into the Windows telnet application, the login procedure works fine!

In the main application, I'm using the OnReceive event of my CSocket class to respond to data sent by the server. If OnReceive is triggered, a UI thread receives a CEvent telling it to run a function that contains the receive function. The other way round, after receiving all data from the buffer, another UI thread gets a CEvent notification to send the appropriate reply. Until finishing with step (2), this works fine so far. The 2 additional thread CSockets used for receiving and sending data are attached to the main application's socket handle.

Anyone who can help me plz?