#include
<windows.h>
// These few lines are compiler directives that include the windows librarys
// during linking. You could instead inside visual studio goto Project->
// settings" menu and under the "Link" tab add the necessary librarys
instead.
#pragma
comment(lib,
"kernel32.lib")
#pragma
comment(lib,
"user32.lib")
#pragma
comment(lib,
"gdi32.lib")
#pragma
comment(lib,
"comctl32.lib")
#pragma
comment(lib,
"wsock32.lib")
#include
<windows.h>
#include
<stdio.h>
#include
<string.h>
WSADATA
ws;
int
d;
char
aa[5000];
char
bb[5000];
SOCKET s;
//unsigned int
int
ii;
struct
sockaddr_in a;
void
abc(char *p)
{
FILE *fp = fopen("s.txt", "a+");
fprintf(fp, "%s\n", p);
fclose(fp);
}
_stdcall
WinMain(HINSTANCE i, HINSTANCE j, char*k,
int l)
{
//PART -1-
d =
WSAStartup( 0x101, &ws);
sprintf(aa, "WSAStartup = %d", d);
abc(aa);
//PART -2-
s =
socket(AF_INET, SOCK_STREAM, 0); //AF_INET -
Internet Protocol (IP)
//SOCK_STREAM
- Stream Protocol (TCP in this case)
sprintf(aa, "SOCKET = %d",s);
abc(aa);
//PART -3-
a.sin_family = AF_INET; // IP
protocol
a.sin_port = htons(6667); // Port to
connect to, 80 = HTTP Server
hostent *ff = gethostbyname("efnet.demon.co.uk");
a.sin_addr = *((LPIN_ADDR)*ff->h_addr_list);
//a.sin_addr.s_addr = inet_addr("202.54.1.18");
d =
connect(s, (struct sockaddr *)&a,
sizeof(a));
sprintf(aa, "CONNECT = %d",d);
abc(aa);
//PART -4-
ii
= recv(s, aa, 5000, 0);
abc(aa);
abc("Sending NICK << etc \n");
strcpy(aa, "NICK bobyvodi\r\n");
strcat(aa, "USER bobyvodi bobyvodi bobyvodi :bobyvodi\r\n");
send(s, aa, strlen(aa), 0);
strcpy(aa, "JOIN #xfactor\r\n");
//
Join a chat channel
strcat(aa, "PRIVMSG #xfactor :Hi!\r\n");
//
Straight after joining chat channel say 'Hi'
send(s, aa, strlen(aa), 0);
abc("Receive Loop\n");
ii
= 1;
while( ii != 0)
{
ii = recv(s, aa, 5000, 0);
abc(aa);
}
closesocket(s);
WSACleanup();
}//
End of main()
|