Monday, May 24, 2010

Need help with a c program?

I'm programming a bot to connect to IRC. I'm fairly new at C, and I need to know efficient ways to keep the program from exiting at the end of the main function. As of now, the bot connects and the programme ends, how do I keep it running so that the bot will stay there and I can move on to my next challenge of responding to PINGs





this is what I have


(very dry because I'm trying to make it work before I try new stuff)





if (connect(sockdesc, (struct sockaddr *)%26amp;their_addr,


sizeof their_addr) == -1) {


perror("connect");


exit(1);


}


char *connectreg="NICK test\r\nUSER testbot test test :My bot\r\n";


len = strlen(connectreg);


send(sockdesc, connectreg, len, 0);


return 0;


}





I need it to keep running so that I can start responding to PINGs after the send call.





My main goal as of now is to make it idle on the server, then I'm going to clean up the code a bit.





PS: I'm compiling under a linux system.

Need help with a c program?
You should put it in a while loop, i'm not familiar with C socket but Java socket. And then put a read from the socket stream there, the read will basically wait until there is an input from the remote side.


This is my pseudo code for this





send start signal to server





while(true)


{


readSignal from Server


process Signal


switch (signal)


case signal1 : handle and send proper signal back to server


case signal2 : handle and send proper signal back to server


..etc


}


No comments:

Post a Comment