哇!居然有几个人来问我要SOCKET 的代码,说是菜鸟想学学,
TMD烦死了.高手快点走,这里会让你呕吐的.
这里写个超简单的代码,呵呵,看不懂,也不要问我啦
我在VC6.0+XP同过,,呵呵~
// sockcli01.cpp : Defines the entry point for the console application.//
#include "stdafx.h"#include "winsock2.h"#include <conio.h>
#define port 80
void main()
{ WSADATA wsaData; WSAStartup(MAKEWORD(2,2), &wsaData); SOCKET sock; sock = socket(AF_INET, SOCK_STREAM, 0); //错误处理 if(sock==INVALID_SOCKET) { printf("SOCKET有问题. /r/n"); } sockaddr_in sin; sin.sin_addr.s_addr = inet_addr("61.140.60.90"); sin.sin_family = AF_INET; sin.sin_port = htons(port); int icnn = connect(sock, (sockaddr*)&sin, sizeof (sin)); //错误处理 if (icnn == SOCKET_ERROR) { printf("连不上--%d--/n", GetLastError()); } char data[1024]; memset(data, 'c', 1024); send(sock, data, 1024, 0); WSACleanup();
printf("恭喜你,你连上了");
printf("而且还发了1024个字节过去.");
printf("用这个程序拼命发,你就是黑客了,呵呵."); getch(); return 0;}
