Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
#include #include #include #include #include int main(int argc, char** argv) { // 1. Create the socket int sock; if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { printf("Could not create socket for connection to server."); return 0; } // 2. Set the server address struct sockaddr_in srv_addr; memset(&srv_addr, 0, sizeof(struct sockaddr_in)); srv_addr.sin_family = AF_INET; srv_addr.sin_addr.s_addr = inet_addr("137.112.18.53"); srv_addr.sin_port = htons(80); // 3. Connect to the server and run the loop. if (connect(sock, (struct sockaddr*) &srv_addr, sizeof(struct sockaddr_in)) < 0) { printf("Could not connect to server."); return 0; } // 4. Send request -- you should really check return values. send(sock, "GET /class/csse/csse132/1516c/ HTTP/1.1\n", 40, 0); send(sock, "Host: www.rose-hulman.edu\n\n", 29, 0); // 5. Read response char buf[128]; int len = 0; // Usually, it is a bad idea to recv in a loop. But here is a crude way to // receive all the content from the web server. while ((len = recv(sock, buf, 127, 0)) > 0) { buf[len] = '\0'; printf("%s", buf); } // 6. Clean up close(sock); return 0; }