Get data from web browser using posix threads C++

Started by
23 comments, last by hplus0603 13 years, 1 month ago
Well i guess what you suggest is the same with this ?



pthread_mutex_lock(&mutex);
if(socketPair->counter == 2)

{
socketPair->counter--;
if(socketPair->counter == 0)
{
delete socketPair->clientProxySocket;
delete socketPair->proxyServerSocket;
delete socketPair;
}
}
pthread_mutex_unlock(&mutex);







Doing this it didnt crashed at all. I opened many sites including watching video from youtube, from 25 sites that i have in my Speed Dial in Opera only 6 of them didint open, the program didnt crashed, it loads only a few from site than remains block. The strange thing is that all 6 of them are from my country, I didnt find a foreign site that hasnt work. What could be the problem ?

Another anoing think is that now even if I am doing nothing the programs still tries to send() and recv() and gives me errors like :



No error
Error receiving bytes from server
Error in Connect()No error
You are connected !!!

CONNETING TO :127.0.0.1 80
Remote host closed connection
Error receiving bytes from client
Error receiving data




And after this (if i dont do nothing for a few minutes) it doesnt work anymore, i have to stop it and run again.

Advertisement

Doing this it didnt crashed at all. I opened many sites including watching video from youtube, from 25 sites that i have in my Speed Dial in Opera only 6 of them didint open, the program didnt crashed, it loads only a few from site than remains block. The strange thing is that all 6 of them are from my country, I didnt find a foreign site that hasnt work. What could be the problem ?


Youtube forbids proxying and caching of its content. It pushes the TCP and HTTP corner cases and is very likely to break any non-compliant and even many compliant proxying attempts. At some point in the past it appeared as if they were deliberately closing or misreporting status of the connection.

Either way, at least as far as youtube goes, proxying is against EULA, so they are technically free to do anything they want.

If you want to access youtube, they provide an API which can be used to access the videos under certain obvious restrictions. For circumventing the region ban, rumor has it there are certain ways but they require payment.

For general HTTP proxying, squid (and others) are world-tested proxies.
if you want to have a different point of presence on the internet, you should make arrangements with a VPN provider.
If you want to establish a TCP tunnel, I suggest using SSH with port forwarding.
If you want to run regular HTTP proxying, I suggest using Squid or something similar.
If you want a good answer to your question, I suggest you describe:
- what problem you're trying to solve
- how you're trying to solve it
- what particular symptoms you've seen
- what you've already tried to solve the problem
- posting code that's relevant to the symptoms you're posting
enum Bool { True, False, FileNotFound };
I'm trying to surf webpages with my proxy program on, but a couple of sites dont load only 20-30% of the content, and few ones loads lets say 97%. Maybe my problems are in my 2 threads that transfers data, altough after Drew_Benton pointed out that a thread may start and finish before the other ones starts , I thought that everything is ok now. Program didint crashed anymore. Maybe there is something still wrong with it, that I can see. So i show you how my thread looks now (the other one works almost the same):



void* client_server(void* arg)
{
pthread_detach(pthread_self());

char data[65536];
SocketPair* socketPair = (SocketPair*)arg;

pthread_mutex_lock(&mutex);
socketPair->counter++;
pthread_mutex_unlock(&mutex);

while(true)
{
// First, receive as many bytes as possible
int bytes_recv = socketPair->clientProxySocket->Recv(data, sizeof(data));

// 0 for disconnect, -1 for error
if( bytes_recv <= 0)
{
cout << "Error receiving bytes from client" << endl;
break;
}

// Now try to send all the bytes
int bytes_sent = socketPair->proxyServerSocket->Send(data, bytes_recv);

// Debugging info
cout <<"Received from client: " << bytes_recv << endl;
cout << "Sent to web server: " << bytes_sent << endl;

// On success, bytes_sent should equal bytes_recv
if( bytes_sent != bytes_recv )
{
cout << "Error, didnt send all bytes from client to server" << endl;
break;
}
}

pthread_mutex_lock(&mutex);
if(socketPair->counter == 2)
{
socketPair->counter--;
if(socketPair->counter == 0)
{
delete socketPair->clientProxySocket;
delete socketPair->proxyServerSocket;
delete socketPair;
}
}
pthread_mutex_unlock(&mutex);

return NULL;
}



I'm trying to surf webpages with my proxy program on, but a couple of sites dont load only 20-30% of the content,



What have you actually tried to debug this problem?
What does the proxy program print, if anything? How does it exit the infinite loop?
Your counter test will never hit the counter==0 case, btw, given that you test that counter==2 and then decrement only once. Assuming you always hold the mutex when changing the counter, there's no way that that code can be hit.

If you haven't yet tried capturing the incoming and outgoing data using "tcpdump -s 10000 -i any" (or Wireshark, if the proxy runs on Windows), then I suggest you to this. It will allow you to see what data comes in and goes out of your proxy.
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement