1 #include <windows.h>
2 #include <winsock.h>
3 #include <stdio.h>
4 #pragma comment(lib, "ws2_32.lib")
5
6 #define CS_ERROR 1
7 #define CS_OK 0
8
9 void sError(char*);
10
11 int main()
12 {
13
14 WORD version;
15 WSADATA wsaData;
16 int rVal=0;
17
18 version = MAKEWORD(1,1);
19
20 WSAStartup(version,(LPWSADATA)&wsaData);
21
22 LPHOSTENT hostEntry;
23
24 //store information about the server
25 //hostEntry = gethostbyname("hibbert");
26
27 // if(!hostEntry)
28 // {
29 // printf("Failed gethostbyname()");
30 // //WSACleanup();
31 // return CS_ERROR;
32 // }
33
34 //create the socket
35 SOCKET theSocket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
36
37 if(theSocket == SOCKET_ERROR)
38 {
39 sError("Failed socket()");
40 return CS_ERROR;
41 }
42 //Fill in the sockaddr_in struct
43 SOCKADDR_IN serverInfo;
44 int ip = inet_addr("192.168.1.67");
45 serverInfo.sin_family = PF_INET;
46 serverInfo.sin_addr.S_un.S_addr = ip;
47
48 serverInfo.sin_port = htons(8888);
49
50 rVal=connect(theSocket,(LPSOCKADDR)&serverInfo, sizeof(serverInfo));
51 if(rVal==SOCKET_ERROR)
52 {
53 printf("Failed connect()");
54 return CS_ERROR;
55 }
56 printf("connect() success\n");
57
58 char buf[512] = "hello you fucking socket";
59 for (int i =0;i < 10; i++)
60 {
61 send(theSocket, buf, 512, 0);
62 printf("send over\n");
63 }
64
65 closesocket(theSocket);
66 WSACleanup();
67 //MessageBoxA(NULL, "Connection was made", "SOCKET", MB_OK);
68 return CS_OK;
69 }
70
71 void sError(char *str)
72 {
73 //MessageBoxA(NULL, str, "SOCKET ERROR", MB_OK);
74 WSACleanup();
75 }
76