Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- using namespace std;
- int main()
- {
- int s = socket(AF_INET, SOCK_STREAM, 0);
- if(s < 0)
- {
- cout << "socket error" << endl;
- return 1;
- }
- struct sockaddr_in addr;
- addr.sin_family = AF_INET;
- addr.sin_port = htons(80);
- addr.sin_addr.s_addr = inet_addr("91.198.174.225");
- if(connect(s, (struct sockaddr *)&addr, sizeof(addr)) < 0)
- {
- cout << "connect error" << endl;
- return 1;
- }
- char msg[] = "GET /wiki/Maemo HTTP/1.1\nHost: ru.wikipedia.org\nUser-Agent: Mozilla/5.0 (X11; U; Linux i686; ru; rv:1.9b5) Gecko/2008050509 Firefox/3.0b5\nAccept: text/html\nConnection: close\n\n";
- cout << "bytes send: " << send(s, msg, sizeof(msg), 0) << endl;
- char buf_tmp[1024];
- while(recv(s, buf_tmp, 1024, 0) > 0)
- cout << buf_tmp << endl;
- // recv(s, buf_tmp, 1024, MSG_WAITALL);
- // cout << buf_tmp << endl;
- close(s);
- return 0;
- }
Add Comment
Please, Sign In to add comment