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

Author Topic: Server - opens connections when no one is connecting  (Read 3354 times)

0 Members and 1 Guest are viewing this topic.

Njifra

  • Guest
Server - opens connections when no one is connecting
« on: May 09, 2015, 04:41:39 pm »
PROBLEM DESCRIPTION:
My server opens new connection every minute or so even tho no one is connecting... And sometimes "receiving" that connection lasts more then 10 sec, which blocks my whole server (in that period it cant receive any messages that are sent from client...). Then connected (real) clients get disconnected cuz I use "ping" messages to check if client is still connected.

This didnt happen before I forwarded port for my server... I use TCP sockets.

I hope you understand what I'm trying to say... My project is big and this really annoys me...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Laurent Gomila - SFML developer

Njifra

  • Guest
Re: Server - opens connections when no one is connecting
« Reply #2 on: May 16, 2015, 01:24:16 pm »
This happens when I open server:


But no one is really connecting!
It should write "[MESSAGE] User sent 'connect' message" if "real" client connects.
Also, then my client cant connect beacuse server is busy with receiving all those connections...

Here is code for receiving connections:
while (!done)
{
        if (!selector.wait(sf::seconds(8.0f)))
                continue;

        #pragma region NEW CONNECTION HANDLE
        if (selector.isReady(listener)) {
                Player m_pl;
                sf::TcpSocket *socket = new sf::TcpSocket;
                listener.accept(*socket);
                       
                #pragma region INIT PACKET
                sf::Packet initPacket;
                if (socket->receive(initPacket) == sf::Socket::Done) {
                        std::string msg;
                        initPacket >> msg;
                                if (msg == "connect") {
                                std::cout << "[MESSAGE] User sent \"connect\" message" << std::endl;
                        }
                        else {
                                m_pl.Disconnected = true;
                        }
                }
                #pragma endregion

                cout << "[ACCEPT] Connection from " << socket->getRemoteAddress() << endl;
                // END INITIALIZATION PACKET

                m_pl.Disconnected = false;
                m_pl.Heartbeat.restart();

                m_pl.m_socket = socket;
                pl.push_back(m_pl);
                selector.add(*socket);
                continue;
        }
        #pragma endregion

        //message handling here:
        //...
}
 

Ugh, idk how to explain this...
« Last Edit: May 16, 2015, 01:26:23 pm by Njifra »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Server - opens connections when no one is connecting
« Reply #3 on: May 16, 2015, 02:46:01 pm »
Quote
This didnt happen before I forwarded port for my server...
You'd be surprised if you saw how much connection attempts from the outside are made on public IPs. Bots, hackers, ... if there is absolutely no protection between the outside and your server, then I wouldn't consider this an issue.
Laurent Gomila - SFML developer

Njifra

  • Guest
Re: Server - opens connections when no one is connecting
« Reply #4 on: May 16, 2015, 04:02:25 pm »
But how do they know the port that my server is using? Also, I get new connection every few seconds so its really bugging me... Can't even test the client with my friends... Is there anything I could do to prevent this from happening?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Server - opens connections when no one is connecting
« Reply #5 on: May 16, 2015, 04:03:46 pm »
Fire up Wireshark and see what is actually happening.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Server - opens connections when no one is connecting
« Reply #6 on: May 16, 2015, 04:17:11 pm »
But how do they know the port that my server is using?
Ever heard of port scanners? Like NMap, Angry IP Scanner and many, many more.