Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
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
?
339 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
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

581 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