Help creating IRC bot

mwrazor

New member
Joined
Dec 17, 2003
Messages
1
In previous versions of vb other than .NET, there was "winsock". This was a lot easier to use than the socket class. I am confused with the socket class MAJORLY. Could anybody show me a tutorial that actually works or tell me how i can work the sockets to actually work (my programs so far havent worked). :D
 
Hello and welcome to the Forums!

I am not too familiar with VB .NET, but I do know C# and I am pretty sure its similar across all .NET languages.

So here it is:

Code:
using System.Net;
using System.Net.Sockets;
using System.Collections;

...
Bool bRunning = true;

ArrayList socklist = new ArrayList();
ArrayList socklistcopy;

Socket sockserv = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

sockserv.Bind(new IPEndPoint(IPAddress.Any, 4001));
sockserv.Listen(10);

socklist.Add(sockserv);

while(bRunning)
{
     socklistcopy = new ArrayList(socklist);

     Socket.Select(socklistcopy, null, null, 1);

     foreach(Socket cursock in socklistcopy)
     {
          if(cursock == sockserv)
          {
               socklist.Add( sockserv.Accept() );
          }
          else
          {
               byte [] buffer = new byte[1024];

               int recvbytes = cursock.Recieve(buffer);

               if(recvbytes <= 0)
               {
                     cursock.Close();
                     socklist.Remove(cursock);
               }
               else
               {
                //Do your stuff with the recieved data
               }
           }
     }
}
...

That should help you out, if not you can pm or email me.

Bye,
Mike
 
Back
Top