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

Author Topic: why when i use this code its runs very slow if i make it check set of ports?  (Read 1189 times)

0 Members and 1 Guest are viewing this topic.

VenomOFSilence

  • Newbie
  • *
  • Posts: 2
    • View Profile
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;
}
« Last Edit: September 20, 2022, 08:07:02 pm by eXpl0it3r »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10800
    • View Profile
    • development blog
    • Email
Because it needs to establish a TCP connection with each endpoint and I guess has a default timeout time. So every failing connection waits for the timeout to pass.

If you want to write a port scanner, you're probably better off using existing solutions or using sockets directly, so you can adjust the behavior to your needs.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything