The Code dont print the Blankspace when I type it between words in the message getline it only print first word or last letter but if i write between words any character like -./\_ it will print the full message , Example :
-Without character:
I Write : Hi how Are you
I Recive : Hi
*******
-With character:
I Write : How-how-Are-you?
I Recive : How-how-Are-you?
********
#include <iostream>
#include <SFML/Network.hpp>
using namespace std;
void server() {
sf::TcpListener listener;
listener.listen(5301);
sf::TcpSocket socket;
listener.accept(socket);
cout << "New client connected: " << socket.getRemoteAddress() << endl;
while(true){
char buffer[1024];
size_t received = 0;
socket.receive(buffer, sizeof(buffer), received);
cout << "Client : " << buffer << endl;
string message;
cout << "Enter Message :";
cin >> message;
socket.send(message.c_str(), message.size() + 1);
}
}
void client() {
string consoleInput;
cout << "Input server address: " << endl;
cin >> consoleInput;
sf::TcpSocket socket;
socket.connect(consoleInput, 5301);
while(true){
string message;
cout << ": ";
cin >> message;
socket.send(message.c_str(), message.size() + 1);
char buffer[1024];
size_t received = 0;
socket.receive(buffer, sizeof(buffer), received);
cout << "Server:" << buffer << endl;
}
}
int main()
{
cout << "Client[c] or server[s]? " << endl;
string consoleInput;
cin >> consoleInput;
if (consoleInput == "c")
{
client();
}
else if (consoleInput == "s")
{
server();
}
return 0;
}