I am writing a (http) proxy server in windows, it doesn't work I expect?

This is a discussion on I am writing a (http) proxy server in windows, it doesn't work I expect? within the Networking/Device Communication forums, part of the General Programming Boards category; Code: nfds = sacceptedclient > swebside ? sacceptedclient : swebside; send(swebside, buf, sizeof(buf), 0); ZeroMemory(buf, sizeof(buf)); //tv.tv_sec = 2; //tv.tv_usec ...

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    16

    I am writing a (http) proxy server in windows, it doesn't work I expect?

    Code:
    nfds = sacceptedclient > swebside ? sacceptedclient : swebside;
    	send(swebside, buf, sizeof(buf), 0);
    	ZeroMemory(buf, sizeof(buf));
    	//tv.tv_sec = 2;
    	//tv.tv_usec = 20;
    	while(1)
    	{
    		FD_ZERO(&fds1);
    		FD_SET(sacceptedclient, &fds1);
    		FD_SET(swebside, &fds1);
    		if((j = select(nfds+1, &fds1, NULL, NULL, NULL)) == SOCKET_ERROR)
    			break;
    		//if(j <= 0) break;
    		if(FD_ISSET(swebside, &fds1))
    		{
    			ZeroMemory(buf, sizeof(buf));
    			i = recv(swebside, buf, sizeof(buf), 0);
    			if(i > 0)
    			send(sacceptedclient,buf, i, 0);
    			else break;
    		}
    		if(FD_ISSET(sacceptedclient, &fds1))
    		{
    			ZeroMemory(buf, sizeof(buf));
    			i = recv(sacceptedclient, buf, sizeof(buf), 0);
    			if(i > 0)
    			send(swebside, buf, i, 0);
    			else break;
    		}		
    	}
    I receive http error 400.



    What is the problm?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    > send(swebside, buf, sizeof(buf), 0);
    Why the whole buffer?
    Why not what is just valid data?

    > ZeroMemory(buf, sizeof(buf));
    If you're doing the right thing with lengths in send and recv calls, then all of these are a waste of effort.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fread doesn't work on Windows?
    By 3Nex in forum C Programming
    Replies: 5
    Last Post: 06-05-2010, 08:02 AM
  2. Small HTTP proxy
    By zacs7 in forum Networking/Device Communication
    Replies: 8
    Last Post: 09-11-2007, 03:53 AM
  3. Writing BMP file... doesn't work correctly
    By tin in forum Game Programming
    Replies: 3
    Last Post: 12-28-2005, 03:40 AM
  4. Vector that creates new windows doesn't work (MFC)
    By Shadow12345 in forum Windows Programming
    Replies: 6
    Last Post: 09-10-2002, 07:39 AM
  5. Replies: 6
    Last Post: 01-07-2002, 01:46 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21