Proxy

This is a discussion on Proxy within the C Programming forums, part of the General Programming Boards category; I worked it out. What I did was stored the bytes received in a char pointer, and did the following ...

  1. #16
    Registered User
    Join Date
    Aug 2012
    Posts
    13
    I worked it out. What I did was stored the bytes received in a char pointer, and did the following changes to this function.

    Code:
    bool RECV_MSG ( SOCKET_DATA* PIPE, char *message, char *RECVD_BYTES ) {
    
        ssize_t status;
        
        status = recv( PIPE->m_sock, message, BUFFER, 0 );
        
        if ( status < 0 ) {
            printf ("%c[1;91m - ERROR #%d: Cannot recieve message!%c[0m\n", 27, errno, 27);
            return false;
        } else if ( status == 0 ) {
            printf ("%c[1;95m - WARNING #%d: Could not read from socket, this is OK.%c[0m\n", 27, errno, 27);
            return false;
        } else {
            sprintf( RECVD_BYTES, "%d", ( int ) status ); // This is what I added.
            return true;
        }
    }
    
    bool SEND_MSG ( SOCKET_DATA* PIPE, char *message, char *SEND_BYTES ) {
        
        ssize_t status;
        
        status = send ( PIPE->m_sock, message, atoi ( SEND_BYTES ), 0 );
    
        if (status < 0) {
            printf ("%c[1;91m - ERROR #%d: Cannot send message!%c[0m\n", 27, errno, 27);
            return false;
        } else {
            return true;
        }
    }
    I figured I could use an int pointer, but I didnt know how to work that one, so I used a char* instead. I couldn't be happier, it took me a while to figure this one out. As we speak I'm using this program .

  2. #17
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    383
    An int pointer would definitely be cleaner than passing strings around that ultimately hold integers. int pointers are easy to use too:
    Code:
    void foo(int *bar)
        *bar = 5;
    }
    
    int x;
    foo(&x); // sets x to 5

  3. #18
    Registered User
    Join Date
    Aug 2012
    Posts
    13
    I was trying to do it that way, but I think the mistake I made was putting the '&' before the variable.

    Thanks.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. proxy.pac (proxy auto config) question
    By boreder in forum C Programming
    Replies: 2
    Last Post: 01-20-2009, 03:13 AM
  2. Simple Proxy
    By Lina in forum C Programming
    Replies: 0
    Last Post: 04-01-2007, 01:36 PM
  3. Connecting through a proxy...
    By jverkoey in forum Networking/Device Communication
    Replies: 1
    Last Post: 07-20-2005, 12:53 PM
  4. DNS via proxy
    By iain in forum Tech Board
    Replies: 2
    Last Post: 02-26-2005, 04:59 AM
  5. proxy
    By shiju in forum C Programming
    Replies: 2
    Last Post: 02-21-2004, 09:37 AM

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