CSocket question

CSocket question

Post by Todd Federm » Sat, 18 May 1996 04:00:00



   I'm using CSocket (MFC 4.0) to communicate with a news server. I use
CAsyncSocket::Send() and CAsyncSocket::Receive() to send and receive ASCII
data. My question is: how can I test to see if there's any data in the
incoming buffer? If I use CAsyncSocket::Receive() when there's no data coming
in, my app just freezes. How do I get around this? Thanks...

     Todd Federman         | Dennis Miller on Art:
                           | ---------------------

                           | Mapplethorpe's bullwhip up the ass photo. One
  (this space for rent)    | man's homo* statement is another man's
                           | unfortunate incident at the proctologist's.
<----------------- adjust your newsreader to this width ----------------->

 
 
 

CSocket question

Post by Chris Marriot » Sat, 18 May 1996 04:00:00




Quote:>I'm using CSocket (MFC 4.0) to communicate with a news server. I use
>CAsyncSocket::Send() and CAsyncSocket::Receive() to send and receive ASCII
>data. My question is: how can I test to see if there's any data in the
>incoming buffer? If I use CAsyncSocket::Receive() when there's no data coming
>in, my app just freezes. How do I get around this? Thanks...

I'm not familiar with these particular classes, but using the socket API
directly, you'd call "select" with a timeout of zero to see if any data
is waiting to be received.

Chris

--------------------------------------------------------------------------
 Chris Marriott, Warrington, UK      | Author of SkyMap v3 award-winning

            For full info, see http://www.execpc.com/~skymap  
      Author member of Association of Shareware Professionals (ASP)
--------------------------------------------------------------------------

 
 
 

CSocket question

Post by Mark Webb-Johnso » Sat, 18 May 1996 04:00:00



>    I'm using CSocket (MFC 4.0) to communicate with a news server. I use
> CAsyncSocket::Send() and CAsyncSocket::Receive() to send and receive ASCII
> data. My question is: how can I test to see if there's any data in the
> incoming buffer? If I use CAsyncSocket::Receive() when there's no data coming
> in, my app just freezes. How do I get around this? Thanks...

There's a handle little IOCtl call you can use:

  DWORD avail = 0;
  m_sock->IOCtl(FIONREAD,&avail);
  // avail now contains number of bytes available to be read

Mark Webb-Johnson

 
 
 

CSocket question

Post by Duane Mor » Sun, 19 May 1996 04:00:00



>   I'm using CSocket (MFC 4.0) to communicate with a news server. I use
>CAsyncSocket::Send() and CAsyncSocket::Receive() to send and receive ASCII
>data. My question is: how can I test to see if there's any data in the
>incoming buffer? If I use CAsyncSocket::Receive() when there's no data coming
>in, my app just freezes. How do I get around this? Thanks...

Set yourself up to receive the OnReceive() event from the socket; it
will be called only when there's data.
--


(602) 861-7609; Phoenix, Arizona

 
 
 

CSocket question

Post by Douglas L Stewa » Sun, 19 May 1996 04:00:00




>>I'm using CSocket (MFC 4.0) to communicate with a news server. I use
>>CAsyncSocket::Send() and CAsyncSocket::Receive() to send and receive ASCII
>>data. My question is: how can I test to see if there's any data in the
>>incoming buffer? If I use CAsyncSocket::Receive() when there's no data coming
>>in, my app just freezes. How do I get around this? Thanks...

I don't know if this is the "correct" way to do this, but I created an
app yesterday in which I did this by creating my own class which inherited
CAsyncSocket.  Then I just overrode CAsyncSocket::OnReceive().  Be sure
when you call your Create() you use the  FD_READ flag.

--

 
 
 

1. easy(?) MFC CSocket question

I am attempting to set up a proxy HTTP server using the Microsoft
Foundation Class programming model for Windows Sockets.  The client
sets up their browser to send their HTTP request packet to the local
host (127.0.0.1) on an arbitrarily chosen port 2742.  My proxy listens
to 2742 and intercepts this request.  Everything works up to this
point.  My proxy then sends the request on to the web server specified
in the request...  but when the proxy tries to intercept the web
server's reply, it's execution seems to get lost somewhere in the
CSocket code.  Here is my "FetchReply" function source code:

CString FetchReply(CString Request)
{

CString Reply;
int HostAddressPos, HostAddressEndPos;

//First I extract the host name from the GET request I have already
//successfully intercepted from the browser and passed to this function
//via the "Request" CString parameter
HostAddressPos = Request.Find("Host: "); // The host name is contained
//in the request on a "Host: " line, i.e.: "Host: www.thehost.com"
HostAddressPos+=6; // Forward to the beginning of the actual address
//(past the "Host: ")
HostAddressEndPos = Request.Find( '\n', HostAddressPos );  // Find the
// end of the line
HostAddress = Request.Mid( HostAddressPos, (HostAddressEndPos -
HostAddressPos - 1) ); // Extract the address - an extra -1 since I
//don't want the '\n'

CSocket cliSock; // Client socket (will request and retrieve from the
//web server)

cliSock.Create( 2743 )
// Will create the client socket on 2743 (arbitrarily chosen)

cliSock.Connect( (LPCTSTR)HostAddress, 80 ))
// Port 80 is the standard HTTP server port

CSocketFile cliSockFile( &cliSock );
// Client reciever Socket File

CArchive cliSockArchive( &cliSockFile, CArchive::load );
// Reciever Socket Archive

CArchive cliSockSendArchive( &cliSockFile, CArchive::store );
// Sender Socket Archive

cliSockSendArchive << Request;  // This seems to work fine

cliSockArchive >> Reply; // Execution does not make it past this line

return Reply;

I do not get any assertion failures or any error messages of any kind -
my proxy just sits there, and if I wait long enough, the browser times
out.

I've tried to follow the CSocket/CSocketFile/CArchive specifications as
closely as possible, but I must be missing something.  Why am I not
getting any reply?

Any ideas?

Thanks,
-Bishop

Sent via Deja.com http://www.deja.com/
Before you buy.

2. Want to buy old systems but no idea what to pay ...

3. CSocket::CancelBlockingCall() question

4. Instruction Scheduling

5. MFC CSocket Nagling Question

6. Terminal to replace keyboard/monitor?

7. CSocket Create Generate C++ Exeception?

8. Job Scheduler?

9. My CSocket::Send() blocks for over 60 seconds on some computers

10. CSocket

11. DLL freezes after calling CSocket.connect(...)

12. CSocket::Receive in a static method

13. CAsyncSocket/CSocket