Thread: IRC get/send messages help

  1. #1
    Registered User
    Join Date
    Jun 2005
    Location
    Philadelphia
    Posts
    16

    Unhappy IRC get/send messages help

    Basically, I've decided to mess around with sockets and create a telnet style IRC client. However, I am having a problem with the program getting the chat from the server channel and simultaneously letting me enter chat to be sent. I've tried a few various ways on how to do this but they all either ended up getting the buffer and not letting me chat or letting me chat and not getting the buffer. The way that I am doing it so far is
    Code:
    	while(true)
    	{
    		while((recv(Socket, buffer, strlen(buffer), 0) != 0) || 
    		      (recv(Socket, buffer, strlen(buffer), 0) != -1))
    		{
    		cout<<buffer;
    		break;
    		}
    		memset(buffer, 0, strlen(buffer));
    		cin>>cintext;
    		strcpy(texttosend, "PRIVMSG #blahhh :");
    		strcat(texttosend, cintext);
    		strcat(texttosend, "\r\n");
    		send(Socket, texttosend, strlen(texttosend), 0);
    		memset(cintext, 0, 255); memset(texttosend, 0, 255);
    	}
    but it's not really letting me enter text/read simultaneously. I can't really logically think of how this would be implemented after trying tons of different approaches, if someone can help me out of this it would be greatly appreciated. Thanks.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > recv(Socket, buffer, strlen(buffer), 0)
    If you've cleared the buffer before, then strlen is going to return 0.
    Use sizeof if your buffer is an array (not a pointer).

    Eg.
    Code:
    while ( (n=recv(Socket, buffer, sizeof(buffer), 0)) > 0 ) {
      // Note that recv DOESN'T append a \0, so use 'n' to determine
      // what to do
    }
    if ( n == 0 ) {
      // closed
    }
    if ( n == -1 ) {
      // error
    }
    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.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Location
    Philadelphia
    Posts
    16
    Thanks for the help, fixed everything and it works just as I wanted it to.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Spy++ view messages posted/sent to a control, or from it?
    By hanhao in forum Windows Programming
    Replies: 2
    Last Post: 06-24-2007, 11:07 PM
  2. IRC, reading the stream
    By Iyouboushi in forum C# Programming
    Replies: 6
    Last Post: 08-03-2006, 05:34 PM
  3. Sending windows messages
    By Ideswa in forum Windows Programming
    Replies: 2
    Last Post: 03-02-2006, 01:27 PM
  4. Some help needed with IRC
    By SaintK in forum C++ Programming
    Replies: 2
    Last Post: 04-04-2004, 07:27 AM