Thread: Socket programming (IRC)

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    32

    Socket programming (IRC)

    I have wrote a simple program for connecting irc servers. It's Ok but the parsing is the thing that i am confused about.
    During the main loop ( while (1) thing) when i try the parse the lines, the bot is exiting like Client exited.Actually when i try this the bot can't stay in server.
    ./bot
    Connection OK.
    Client exited.
    Here is the samples:
    Code:
    void send_nickname_joined(Socket sock, char *buf)
    {
    char *nick;
    nick = strtok(buf, "!");
    clearit(':', nick);
    send_server(sock, "%s has joinied", nick);
    return;
    }
    Code:
    int main ()
    {
    //variables
    //socket routines
    //irc connection routines
    //background routins
    /* Connection Ok. Parsing.. */
    while (1) 
    {
    readaline(sock, buf, sizeof(buf));
    //check pings for pong
    send_nickname_joined(sock, buf);
    }
    }
    When i am commented out "send_nickname_joined(buf);" line the bot stays in server as long as i keep it.
    Any ideas, samples, codes would be appreciated.
    Thanks in advanced.
    Last edited by |HBO|; 12-05-2007 at 10:24 AM.

  2. #2
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    Well, send_nickname_joined, has 2 parameters and you are using it like it only has one... That should trip other warnings too.... are you compiling with -Wall?

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    32
    Quote Originally Posted by Wraithan View Post
    Well, send_nickname_joined, has 2 parameters and you are using it like it only has one... That should trip other warnings too.... are you compiling with -Wall?
    Nope my bad.I updated the code.Please take a look again.
    Last edited by |HBO|; 12-05-2007 at 10:23 AM.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    How are you declaring your buffers?

    Is send_server() really a variadic function (like printf) ?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Aug 2007
    Posts
    32
    Yep, i am using it with macros anyway.
    Accidentally i found the problem. I have forgot using the socket pointer in the parsing function.Anyway, thanks to who helped and will help..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. socket programming question, closing sockets...
    By ursula in forum Networking/Device Communication
    Replies: 2
    Last Post: 05-31-2009, 05:17 PM
  2. IRC, reading the stream
    By Iyouboushi in forum C# Programming
    Replies: 6
    Last Post: 08-03-2006, 05:34 PM
  3. irc socket code
    By lost_in_logic in forum C Programming
    Replies: 3
    Last Post: 08-16-2005, 03:58 AM
  4. when to close a socket
    By Wisefool in forum Networking/Device Communication
    Replies: 5
    Last Post: 11-02-2003, 10:33 AM
  5. socket newbie, losing a few chars from server to client
    By registering in forum Linux Programming
    Replies: 2
    Last Post: 06-07-2003, 11:48 AM