Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8912023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:05:50+00:00 2026-06-15T04:05:50+00:00

Trying to build a proxy server. recv from client -> send to server ->

  • 0

Trying to build a proxy server.
recv from client -> send to server -> recv from server -> send to client.

The proxy receives the correct data from the client.
But after that I recv 0 bytes from the server.

This is the packet i should recv from the client and send to the server

0A 00 2C 01 23 00 0C 00 B3 01

Here is my code;

    //intercept commu by server <-> client

    memset(buffer, 0, buffer_len);

    //recv from client
    if((bytecount = recv(*csock, buffer, buffer_len, 0))== -1){
        fprintf(stderr, "Err: receiving data %d\n", errno);
        return 0;
    }

    //display what we got from the client
    printf("Received bytes %d\n", bytecount);
    for ( int i = 0; i < bytecount; i++ ) {
    printf( "%02x ", static_cast<unsigned char>( buffer[i] ) );
    }
    printf("\n");

    //send to server what we got from the client
    if((gbytecount=send(gsock, buffer, buffer_len, 0))== -1){
    fprintf(stderr, "Error sending data %d\n", errno);
    goto FINISH;
    }


    //recv from server
    if((gbytecount = recv(gsock, buffer, buffer_len, 0))== -1){
        fprintf(stderr, "Error receiving data %d\n", errno);
        return 0;
    }

    printf("Received bytes %d\n", gbytecount);
    for ( int i = 0; i < gbytecount; i++ ) {
    printf( "%02x ", static_cast<unsigned char>( buffer[i] ) );
    }
    printf("\n");   

    //send back to client what we got from the server
    if((bytecount = send(*csock, buffer, buffer_len, 0))== -1){
        fprintf(stderr, "Err: sending data %d\n", errno);
        return 0;
    }

How do I check what the proxy is sending to the server after recv from the client?
And is there something wrong with my logic?


UPDATE

I guess i found the problem, its because of the buffer_len.

Now I have recv() bytes 93. But the server again sends another packet.
What do I do to my code?

Currently my code is:

recv from client -> send to server -> recv from server -> send to client.

How can I make this code like If the client/server sends something, it will

forward it to the other?


UPDATE

Got to solve it. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T04:05:51+00:00Added an answer on June 15, 2026 at 4:05 am

    I don’t know your server and client, but may be server actually close the socket that cause a 0 as result of recv, and the reason of closure may be is that you receive bytecount data from client but send buffer_len data to the server that may cause some invalid data after valid data to sent to the server!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying Build For Archiving application (from Titanium Mobile) with xCode 4.4, but
I am trying to build a socks5 proxy server using codes I found googling
I'm trying to build a proxy module for .NET, but I'm having trouble copying
I am trying to build a dynamic tree. I am getting my data from
I'm trying to build the proxy class for a web service using the wsdl
I'm trying build a method which returns the shortest path from one node to
I'm trying build a MVC framework, but I'm confused about manage themes. Well... I
Problem I am trying to install hudson build server on a windows server through
I am trying to access maven repository from behind proxy. I configured settings.xml correctly
I'm trying to build an object that looks something like this: public class MyObject

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.