Thursday, January 1, 2015

Why won't my bot connect to the irc?

Whenever I run the program I don't get any information back from the server I connected to and also when I check the irc room my bots name is not there. Anybody know why? I am new to using sockets and this is my first project dealing with sockets. Sorry if its an obvious mistake.



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;

namespace ConnectIRC
{
class Program
{
static void Main(string[] args)
{
string ip = "asimov.freenode.net";
string nick = "NICK James10113"; //Nick name for bot
string join = "JOIN #Chataholics";//channel to join
int port = 6667;

const int recvBufSize = 8162;
byte[] recvbBuf = new byte[recvBufSize];
//stores the nick
byte[] nickBuf = Encoding.ASCII.GetBytes(nick);
//Stores the room join
byte[] joinBuf = Encoding.ASCII.GetBytes(join);

Socket conn = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
conn.Connect(ip, port);


for(;;){
byte[] formatter = new byte [conn.Receive(recvbBuf, recvbBuf.Length, SocketFlags.None)];
Console.WriteLine(Encoding.ASCII.GetString(formatter));
if (formatter.Length == 0)
{
conn.Close();
}
}

IPEndPoint serverEndPoint = new IPEndPoint(Dns.Resolve(ip).AddressList[0], port);
conn.Connect(serverEndPoint);



//Sends the nick and join
conn.Send(nickBuf, nickBuf.Length, SocketFlags.None);
conn.Send(joinBuf, joinBuf.Length, SocketFlags.None);








}
}
}




No comments:

Post a Comment