Hello everyone,
I have a problem with TCP sockets. I can only get the socket to send once, then all calls to Send() afterward don`t work.
sf::SocketTCP* Client = static_cast<sf::SocketTCP*>(UserData);
char Buffer[1024];
std::size_t Received;
char * buf2;
for (int i = 0; i < 2; i++) {
Client->Receive(Buffer, sizeof(Buffer), Received);
Buffer[Received] = '\0'; //Nulling the last+1 cell
cout << Buffer;
}
cout << "End of Recv" << endl;
char getpage[] = "NICK lmno \n\rUSER lmno 0 * :lmno\n\rJOIN #mytest\n\rPRIVMSG #mytest :qwertyuiop\0";
Client->Send(getpage, sizeof(getpage)); //This one works
char message[] = "PRIVMSG #mytest :La-di-da\n\r\0";
while (1) {
Client->Receive(Buffer, sizeof(Buffer), Received);
Buffer[Received] = '\0'; //Nulling the last+1 cell
cout << Buffer <<endl;
Client->Send(message, sizeof(message)); // This one does not
cout << "Sent ladida" << endl;
}
Help is very much appreciated.
edit: I tried out something new, and it works, but it has a useless Send()
sender(*Client);
I put this in the while loop
void sender(sf::SocketTCP Client) {
char pong[1024];
memset (pong, '0', (size_t)1024);
strcpy(pong, "PRIVMSG #mytest :qwerty");
//strcat(pong, ping);
strcat(pong, "\n\r");
cout << pong << endl;
Client.Send(pong, sizeof(pong));
Client.Send(pong, sizeof(pong));
char msg[128];
strcpy(msg, "PRIVMSG #mytest :La-Di_da\n\r");
Client.Send(msg, sizeof(msg));
cout << "Sent from sender" << endl;
}
The extra Send() must be there to work. Does anyone know why?
Thanks,
SFI