www.xbdev.net
xbdev - software development
Thursday March 28, 2024
home | contact | Support | Javascipt... so much power in such a few lines of code..

     
 

Javascipt...

so much power in such a few lines of code..

 

IRC Client with WinSock

 

So what is IRC?... Is IRC free?  Who can I talk to?....  IRC is a set of free online chat servers...you can connet to them and speak to anyone you want around the world...transfer files..etc.  Usually you join a server...for example #EFnet....upon joining the server...you join a chat channel....another example is channel #xfactor.

 

I'll take you through a small sample to get you going on the world of programming a IRC chat program.  Once you know what basic data to send and receive, you'll have no problems writing all the other add on stuff...like ping and dcc msg commands.

 

You might want to download mIRC, (www.mirc.com) which is a win32 program and allows you actually chat in the channel...and of course, you can see your little program connect and join the channel....say hello...then sit there..hehe....and if your an op..kick him..hehe

 

Of course if your new to chat programs, I'm sure you'll soon pick it up....people online are always willing to give you help/advice on how to use IRC...so don't despair :)

 

But we'll be approaching it from a programmers persective!  No ordinary's programmers persective...but an xbdev one..where we show you simple...juicy...cool...and fun pieces of code...that enable you to go away actually knowing the real stuff.

 

 

IRC Code - Download
 

#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()

 

 

 

 

 
Advert (Support Website)

 
 Visitor:
Copyright (c) 2002-2024 xbdev.net - All rights reserved.
Designated articles, tutorials and software are the property of their respective owners.