SFI
SFI

Reputation: 23

IRC client - No reply on JOIN

I am writing a IRC client in C++ (with the help of the SFML library), but it is behaving strangely. I send the NICK and USER commands and I can connect to the server, but the JOIN command has many strange thing happening that I have to write "Random code that magically works" to solve. I am pretty sure that the commands adhere to the IRC RFC as well.

I know that the sockets are sending what they are supposed to send and I have verified it with Wireshark, so what I post here is what the message of the packet is. In the following examples the socket is already connected to the IRC server (which in this case is irc.freenode.net)

This works:

char mess[] ="NICK lmno \n\rUSER lmno 0 * :lmno\n\rJOIN #mytest\n\r";
Socket.Send(mess, sizeof(mess));

This does not:

char msg[] = "NICK lmno \r\nUSER lmno 0 * :lmno \r\n";
char msga[] = "JOIN #mytest \r\n";
Socket.Send(msg, sizeof(msg));
Socket.Send(msga, sizeof(msga));

But curiously this works:

char msg[] = "NICK lmno \r\nUSER lmno 0 * :lmno \r\n";
char msga[] = "JOIN #mytest \r\n";
Socket.Send(msg, sizeof(msg));
Socket.Send(msga, sizeof(msga));
Socket.Send(msga, sizeof(msga));

I did do some research on this topic and no one seems to have the same problem. Stranger is that when I tried this in telnet, I only have to send JOIN once. Is anyone able to give me some advice?

Thanks, SFI

Upvotes: 2

Views: 581

Answers (1)

Darcy Rayner
Darcy Rayner

Reputation: 3445

It might have to do with the terminating '\0' character at the end of a c-string. Try

Socket.Send(msg, sizeof(msg) - 1);
Socket.Send(msga, sizeof(msga) - 1);

Upvotes: 4

Related Questions