-1

When i am connecting to an IRC server via telnet everything works fine, but in my program there is no respond from server after the greeting message. What's wrong?

PS when i am sending "JOIN #channel" server responds.

fragment of the code:

while (true)
{
    ret = recv(pocket, buf, 512, 0);
    if (ret == 0 || ret == SOCKET_ERROR)
    {
        printf("Serwer przerwal polaczenie");
        break;
    }
    buf[ret] = '\0';
    input = buf;
    printf("%s\n", input.c_str());
    if (fTime)
    {
        isend(pocket, "USER foox 0 0 :foox");
        isend(pocket, "NICK foobar");
        fTime = false;
    }
    memset(buf, 0, sizeof(buf));
}

isend function:

bool isend(SOCKET socket,std::string message)
{
        int ret = send(socket, message.c_str(), message.size() + 1, 0);
        if (!ret){
        printf("Nie udalo sie wyslac pakietu: \"%s\"", message);
        return false;
    }
    else
        return true;
}
  • Why are you sending .size()+1? For the USER and NICK it doesn't look like you're sending \r\n after each line. – Boofhead Mar 18 '14 at 20:44
  • i corrected it before, but still it isnt working – user3434747 Mar 18 '14 at 20:54
  • Looks like your edits still make a mistake of sending size()+1. You again have not added the \r\n to each. Each line should be properly terminated as per RFC. – Boofhead Mar 21 '14 at 02:14

2 Answers2

0

Don't read upon connection. Send the NICK and USER information as per RFC 2812. You're doing it in reverse order that is suggested. Both NICK and USER lines need to be correctly terminated with \r\n and then you can read.

Don't send message.size()+1 - do send message.size(). I don't understand why you were sending message.size()+1 and you didn't answer why in my comments.

If you get stuck I suggest using something like Wireshark with an unencrypted connection and log how IRC clients manage it.

Boofhead
  • 511
  • 1
  • 3
  • 7
0

You have three issues:

  1. You do a blocking read, which will wait forever if there's nothing to read.

  2. You need to send a carriage return and newline after each line.

  3. You don't want to send the terminating zero byte.

David Schwartz
  • 179,497
  • 17
  • 214
  • 278