I am trying to implement this drawing using posix threads and sockets(TCP).
Code:
webserver <--- proxy <--- client
webserver ---> proxy ---> client
I tried using 4 threads for every arrow.I want to ask if i implement the code good,doesnt send data as it supposed too.Here is my code:
Code:
void* client_proxy(void* arg)
{
    TCPSocket* sock = (TCPSocket*)arg;
    pthread_mutex_lock(&mutex);
    numbytes = sock->Recv(data, sizeof(data));
    pthread_mutex_unlock(&mutex);
    cout <<"Received from client: " << numbytes << endl;
}

void* proxy_server(void* arg)
{
    ClientSocket* client = (ClientSocket*)arg;
    pthread_mutex_lock(&mutex);
    numbytes2 = client->Send(data, numbytes);
    pthread_mutex_unlock(&mutex);
    cout << "Sent to web server: " << numbytes << endl;
}

void* server_proxy(void* arg)
{
    ClientSocket* client = (ClientSocket*)arg;
    pthread_mutex_lock(&mutex2);
    numbytes2 = client->Recv(data2, sizeof(data2));
    cout <<"Received from web server: " << numbytes2 << endl;
    pthread_mutex_unlock(&mutex2);
}

void* proxy_client(void* arg)
{
    TCPSocket* sock = (TCPSocket*)arg;
    pthread_mutex_lock(&mutex2);
    numbytes = sock->Send(data2, numbytes2);
    pthread_mutex_unlock(&mutex2);
    cout << "Sent to client: " << numbytes << endl;
}
PS: the web server is a browser,and it always send data to load the page only 40-50% of it. Then it remains stuck.