Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - VenomOFSilence

Pages: [1]
1
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;
}
 

2
This is the code , if i make it check set ports by using for loop it runs very slow.
#include <iostream>
#include <SFML/Network.hpp>
#include <string>

static bool port_is_open(const std::string& address, int port)
{
    return (sf::TcpSocket().connect(address, port) == sf::Socket::Done);
}

int main1()
{
    if (port_is_open("127.0.0.1", 445))
        std::cout << "OPEN" << std::endl;
    else
        std::cout << "CLOSED" << std::endl;
    return 0;
}

Pages: [1]
anything