?
Solved

sending "HTTP/1.0 200 OK \r\n" does not work in the browser(ie5.0)!

Posted on 2003-03-24
2
Medium Priority
?
270 Views
Last Modified: 2013-11-20
Hi,
   I am writing a proxy server with C using vc++ 6.0
   I am using WIN32 API and NOT USING MFC. My problem is
   sending the basic HTTP headers just does not work in
   the browser! I have included the code. Pleash HELP!

#include "main.h"    
void main()
{
     WSAData wData;
     SOCKET serverSocket;    
     SOCKADDR_IN serverAddr;

     WSAStartup(MAKEWORD(2, 0), &wData);

     serverSocket=socket(AF_INET, SOCK_STREAM, 0);

     serverAddr.sin_family=AF_INET;
     serverAddr.sin_port=htons(8080);
     serverAddr.sin_addr.s_addr=inet_addr("192.168.0.1");
     bind(serverSocket, (struct sockaddr *)&serverAddr, sizeof
                            (serverAddr));

     listen(serverSocket, 10);

     while(true)
     {
          SOCKADDR_IN clientAddr;
          int clientAddrLen=sizeof(clientAddr);

          SOCKET client=accept(serverSocket, (struct sockaddr *)      
                                     &clientAddr, &clientAddrLen);          
          char * resp="HTTP/1.0 200 OK\r\n"
                   "Content-type: text/html\r\n\r\n"
                   "<html>ASHOK</html>\r\n";

          send(client, resp, strlen(resp), 0);

          shutdown(client, 0x2);          
          closesocket(client);
     }

     WSACleanup();
}

0
Comment
Question by:kashokshenoy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Accepted Solution

by:
cmaryus earned 1740 total points
ID: 8201109
you MUST call receive first.
when connecting to a server the browser send a request, then it reads for the answer from the server.
so after accept, do :
char szRecvbuf[2049];
recv(client, szRecvbuf, 2048, 0);
then you can send the buffer
0
 

Author Comment

by:kashokshenoy
ID: 8211809
Thanks for the timely help.

You saved my scalp!!!
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question